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