nested-cache.js 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(
  41. new Vue({
  42. render: h => h(app, { props: { id: 1 } })
  43. })
  44. )
  45. }