1
1
// @flow
2
2
3
- import addSlots from './add-slots'
3
+ import createSlotVNodes from './add-slots'
4
4
import addMocks from './add-mocks'
5
- import addAttrs from './add-attrs'
6
- import addListeners from './add-listeners'
7
- import addProvide from './add-provide'
5
+ // import addAttrs from './add-attrs'
6
+ // import addListeners from './add-listeners'
7
+ // import addProvide from './add-provide'
8
8
import { addEventLogger } from './log-events'
9
9
import { createComponentStubs } from './stub-components'
10
10
import { throwError } from './util'
@@ -14,7 +14,6 @@ import extractOptions from '../options/extract-options'
14
14
import deleteMountingOptions from '../options/delete-mounting-options'
15
15
import createFunctionalComponent from './create-functional-component'
16
16
import cloneDeep from 'lodash/cloneDeep'
17
- import { componentNeedsCompiling } from './validators'
18
17
19
18
export default function createConstructor (
20
19
component : Component ,
@@ -28,28 +27,30 @@ export default function createConstructor (
28
27
addMocks ( mountingOptions . mocks , vue )
29
28
}
30
29
31
- if ( ( component . options && component . options . functional ) || component . functional ) {
30
+ if ( component . functional ) {
32
31
component = createFunctionalComponent ( component , mountingOptions )
33
32
} else if ( mountingOptions . context ) {
34
33
throwError (
35
34
'mount.context can only be used when mounting a functional component'
36
35
)
37
36
}
38
37
39
- if ( mountingOptions . provide ) {
40
- addProvide ( component , mountingOptions . provide , options )
41
- }
38
+ // TODO: Add to parent instance instead.
39
+ // if (mountingOptions.provide) {
40
+ // addProvide(component, mountingOptions.provide, options)
41
+ // }
42
42
43
- if ( componentNeedsCompiling ( component ) ) {
43
+ if ( ! component . render &&
44
+ ( component . template || component . extends ) &&
45
+ ! component . functional ) {
44
46
compileTemplate ( component )
45
47
}
46
48
47
49
addEventLogger ( vue )
48
50
49
- const Constructor = vue . extend ( component )
50
-
51
51
const instanceOptions = { ...options }
52
52
deleteMountingOptions ( instanceOptions )
53
+ // delete instanceOptions.propsData // TODO: move that to deleteMountingOptions
53
54
54
55
if ( mountingOptions . stubs ) {
55
56
instanceOptions . components = {
@@ -59,17 +60,41 @@ export default function createConstructor (
59
60
}
60
61
}
61
62
62
- const vm = new Constructor ( instanceOptions )
63
+ // const vm = new Constructor(instanceOptions)
64
+ const BaseConstructor = vue . extend ( component )
65
+ const Constructor = BaseConstructor . extend ( instanceOptions )
66
+
67
+ const Parent = vue . extend ( {
68
+ provide : mountingOptions . provide ,
69
+ data ( ) {
70
+ return {
71
+ propsData : options . propsData || { } ,
72
+ attrs : mountingOptions . attrs || { } ,
73
+ listeners : mountingOptions . listeners || { }
74
+ }
75
+ } ,
76
+ render ( h ) {
77
+ const slots = mountingOptions . slots
78
+ ? createSlotVNodes . call ( this , mountingOptions . slots )
79
+ : undefined
80
+ const vnode = h ( Constructor , {
81
+ ref : 'vm' ,
82
+ props : this . propsData ,
83
+ on : this . listeners ,
84
+ attrs : this . attrs ,
85
+ ...instanceOptions
86
+ } , slots )
87
+
88
+ return vnode
89
+ }
90
+ } )
63
91
64
- addAttrs ( vm , mountingOptions . attrs )
65
- addListeners ( vm , mountingOptions . listeners )
92
+ const parent = new Parent ( ) . $mount ( )
66
93
67
- vm . $_mountingOptionsSlots = mountingOptions . slots
68
- vm . $_originalSlots = cloneDeep ( vm . $slots )
94
+ const vm = parent . $refs . vm
69
95
70
- if ( mountingOptions . slots ) {
71
- addSlots ( vm , mountingOptions . slots )
96
+ return {
97
+ parent,
98
+ vm
72
99
}
73
-
74
- return vm
75
100
}
0 commit comments