nested-cache.js 963 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Vue from '../../../dist/vue.runtime.common.js'
  2. function createRegisterFn (id) {
  3. return function (context) {
  4. context = context || this.$vnode.ssrContext
  5. context.registered.push(id)
  6. }
  7. }
  8. function addHooks (comp) {
  9. const hook = createRegisterFn(comp.name)
  10. return Object.assign(comp, {
  11. _ssrRegister: hook,
  12. beforeCreate: hook
  13. })
  14. }
  15. const grandchild = addHooks({
  16. name: 'grandchild',
  17. props: ['id'],
  18. serverCacheKey: props => props.id,
  19. render (h) {
  20. return h('div', '/test')
  21. }
  22. })
  23. const child = addHooks({
  24. name: 'child',
  25. props: ['id'],
  26. serverCacheKey: props => props.id,
  27. render (h) {
  28. return h(grandchild, { props: { id: this.id }})
  29. }
  30. })
  31. const app = addHooks({
  32. name: 'app',
  33. props: ['id'],
  34. serverCacheKey: props => props.id,
  35. render (h) {
  36. return h(child, { props: { id: this.id }})
  37. }
  38. })
  39. export default () => {
  40. return Promise.resolve(new Vue({
  41. render: h => h(app, { props: { id: 1 }})
  42. }))
  43. }