@@ -29,52 +29,14 @@ export function initLifecycle (vm: Component) {
29
29
vm . $refs = { }
30
30
31
31
vm . _watcher = null
32
- vm . _inactive = false
32
+ vm . _inactive = null
33
+ vm . _directInactive = false
33
34
vm . _isMounted = false
34
35
vm . _isDestroyed = false
35
36
vm . _isBeingDestroyed = false
36
37
}
37
38
38
39
export function lifecycleMixin ( Vue : Class < Component > ) {
39
- Vue . prototype . _mount = function (
40
- el ?: Element | void ,
41
- hydrating ?: boolean
42
- ) : Component {
43
- const vm : Component = this
44
- vm . $el = el
45
- if ( ! vm . $options . render ) {
46
- vm . $options . render = createEmptyVNode
47
- if ( process . env . NODE_ENV !== 'production' ) {
48
- /* istanbul ignore if */
49
- if ( vm . $options . template && vm . $options . template . charAt ( 0 ) !== '#' ) {
50
- warn (
51
- 'You are using the runtime-only build of Vue where the template ' +
52
- 'option is not available. Either pre-compile the templates into ' +
53
- 'render functions, or use the compiler-included build.' ,
54
- vm
55
- )
56
- } else {
57
- warn (
58
- 'Failed to mount component: template or render function not defined.' ,
59
- vm
60
- )
61
- }
62
- }
63
- }
64
- callHook ( vm , 'beforeMount' )
65
- vm . _watcher = new Watcher ( vm , function updateComponent ( ) {
66
- vm . _update ( vm . _render ( ) , hydrating )
67
- } , noop )
68
- hydrating = false
69
- // manually mounted instance, call mounted on self
70
- // mounted is called for render-created child components in its inserted hook
71
- if ( vm . $vnode == null ) {
72
- vm . _isMounted = true
73
- callHook ( vm , 'mounted' )
74
- }
75
- return vm
76
- }
77
-
78
40
Vue . prototype . _update = function ( vnode : VNode , hydrating ?: boolean ) {
79
41
const vm : Component = this
80
42
if ( vm . _isMounted ) {
@@ -115,62 +77,6 @@ export function lifecycleMixin (Vue: Class<Component>) {
115
77
// updated in a parent's updated hook.
116
78
}
117
79
118
- Vue . prototype . _updateFromParent = function (
119
- propsData : ?Object ,
120
- listeners : ?Object ,
121
- parentVnode : VNode ,
122
- renderChildren : ?Array < VNode >
123
- ) {
124
- const vm : Component = this
125
-
126
- // determine whether component has slot children
127
- // we need to do this before overwriting $options._renderChildren
128
- const hasChildren = ! ! (
129
- renderChildren || // has new static slots
130
- vm . $options . _renderChildren || // has old static slots
131
- parentVnode . data . scopedSlots || // has new scoped slots
132
- vm . $scopedSlots !== emptyObject // has old scoped slots
133
- )
134
-
135
- vm . $options . _parentVnode = parentVnode
136
- vm . $vnode = parentVnode // update vm's placeholder node without re-render
137
- if ( vm . _vnode ) { // update child tree's parent
138
- vm . _vnode . parent = parentVnode
139
- }
140
- vm . $options . _renderChildren = renderChildren
141
-
142
- // update props
143
- if ( propsData && vm . $options . props ) {
144
- observerState . shouldConvert = false
145
- if ( process . env . NODE_ENV !== 'production' ) {
146
- observerState . isSettingProps = true
147
- }
148
- const props = vm . _props
149
- const propKeys = vm . $options . _propKeys || [ ]
150
- for ( let i = 0 ; i < propKeys . length ; i ++ ) {
151
- const key = propKeys [ i ]
152
- props [ key ] = validateProp ( key , vm . $options . props , propsData , vm )
153
- }
154
- observerState . shouldConvert = true
155
- if ( process . env . NODE_ENV !== 'production' ) {
156
- observerState . isSettingProps = false
157
- }
158
- // keep a copy of raw propsData
159
- vm . $options . propsData = propsData
160
- }
161
- // update listeners
162
- if ( listeners ) {
163
- const oldListeners = vm . $options . _parentListeners
164
- vm . $options . _parentListeners = listeners
165
- updateComponentListeners ( vm , listeners , oldListeners )
166
- }
167
- // resolve slots + force update if has children
168
- if ( hasChildren ) {
169
- vm . $slots = resolveSlots ( renderChildren , parentVnode . context )
170
- vm . $forceUpdate ( )
171
- }
172
- }
173
-
174
80
Vue . prototype . $forceUpdate = function ( ) {
175
81
const vm : Component = this
176
82
if ( vm . _watcher ) {
@@ -217,6 +123,141 @@ export function lifecycleMixin (Vue: Class<Component>) {
217
123
}
218
124
}
219
125
126
+ export function mountComponent (
127
+ vm : Component ,
128
+ el : ?Element ,
129
+ hydrating ?: boolean
130
+ ) : Component {
131
+ vm . $el = el
132
+ if ( ! vm . $options . render ) {
133
+ vm . $options . render = createEmptyVNode
134
+ if ( process . env . NODE_ENV !== 'production' ) {
135
+ /* istanbul ignore if */
136
+ if ( vm . $options . template && vm . $options . template . charAt ( 0 ) !== '#' ) {
137
+ warn (
138
+ 'You are using the runtime-only build of Vue where the template ' +
139
+ 'option is not available. Either pre-compile the templates into ' +
140
+ 'render functions, or use the compiler-included build.' ,
141
+ vm
142
+ )
143
+ } else {
144
+ warn (
145
+ 'Failed to mount component: template or render function not defined.' ,
146
+ vm
147
+ )
148
+ }
149
+ }
150
+ }
151
+ callHook ( vm , 'beforeMount' )
152
+ vm . _watcher = new Watcher ( vm , function updateComponent ( ) {
153
+ vm . _update ( vm . _render ( ) , hydrating )
154
+ } , noop )
155
+ hydrating = false
156
+ // manually mounted instance, call mounted on self
157
+ // mounted is called for render-created child components in its inserted hook
158
+ if ( vm . $vnode == null ) {
159
+ vm . _isMounted = true
160
+ callHook ( vm , 'mounted' )
161
+ }
162
+ return vm
163
+ }
164
+
165
+ export function updateChildComponent (
166
+ vm : Component ,
167
+ propsData : ?Object ,
168
+ listeners : ?Object ,
169
+ parentVnode : VNode ,
170
+ renderChildren : ?Array < VNode >
171
+ ) {
172
+ // determine whether component has slot children
173
+ // we need to do this before overwriting $options._renderChildren
174
+ const hasChildren = ! ! (
175
+ renderChildren || // has new static slots
176
+ vm . $options . _renderChildren || // has old static slots
177
+ parentVnode . data . scopedSlots || // has new scoped slots
178
+ vm . $scopedSlots !== emptyObject // has old scoped slots
179
+ )
180
+
181
+ vm . $options . _parentVnode = parentVnode
182
+ vm . $vnode = parentVnode // update vm's placeholder node without re-render
183
+ if ( vm . _vnode ) { // update child tree's parent
184
+ vm . _vnode . parent = parentVnode
185
+ }
186
+ vm . $options . _renderChildren = renderChildren
187
+
188
+ // update props
189
+ if ( propsData && vm . $options . props ) {
190
+ observerState . shouldConvert = false
191
+ if ( process . env . NODE_ENV !== 'production' ) {
192
+ observerState . isSettingProps = true
193
+ }
194
+ const props = vm . _props
195
+ const propKeys = vm . $options . _propKeys || [ ]
196
+ for ( let i = 0 ; i < propKeys . length ; i ++ ) {
197
+ const key = propKeys [ i ]
198
+ props [ key ] = validateProp ( key , vm . $options . props , propsData , vm )
199
+ }
200
+ observerState . shouldConvert = true
201
+ if ( process . env . NODE_ENV !== 'production' ) {
202
+ observerState . isSettingProps = false
203
+ }
204
+ // keep a copy of raw propsData
205
+ vm . $options . propsData = propsData
206
+ }
207
+ // update listeners
208
+ if ( listeners ) {
209
+ const oldListeners = vm . $options . _parentListeners
210
+ vm . $options . _parentListeners = listeners
211
+ updateComponentListeners ( vm , listeners , oldListeners )
212
+ }
213
+ // resolve slots + force update if has children
214
+ if ( hasChildren ) {
215
+ vm . $slots = resolveSlots ( renderChildren , parentVnode . context )
216
+ vm . $forceUpdate ( )
217
+ }
218
+ }
219
+
220
+ function isInInactiveTree ( vm ) {
221
+ while ( vm && ( vm = vm . $parent ) ) {
222
+ if ( vm . _inactive ) return true
223
+ }
224
+ return false
225
+ }
226
+
227
+ export function activateChildComponent ( vm : Component , direct ? : boolean ) {
228
+ if ( direct ) {
229
+ vm . _directInactive = false
230
+ if ( isInInactiveTree ( vm ) ) {
231
+ return
232
+ }
233
+ } else if ( vm . _directInactive ) {
234
+ return
235
+ }
236
+ if ( vm . _inactive || vm . _inactive == null ) {
237
+ vm . _inactive = false
238
+ for ( let i = 0 ; i < vm . $children . length ; i ++ ) {
239
+ activateChildComponent ( vm . $children [ i ] )
240
+ }
241
+ callHook ( vm , 'activated' )
242
+ }
243
+ }
244
+
245
+ export function deactivateChildComponent ( vm : Component , direct ? : boolean ) {
246
+ if ( direct ) {
247
+ vm . _directInactive = true
248
+ if ( isInInactiveTree ( vm ) ) {
249
+ return
250
+ }
251
+ }
252
+ if ( ! vm . _inactive ) {
253
+ vm . _inactive = true
254
+ for ( let i = 0 ; i < vm . $children . length ; i ++ ) {
255
+ deactivateChildComponent ( vm . $children [ i ] )
256
+ }
257
+ callHook ( vm , 'deactivated' )
258
+ }
259
+ }
260
+
220
261
export function callHook ( vm : Component , hook : string ) {
221
262
const handlers = vm . $options [ hook ]
222
263
if ( handlers ) {
0 commit comments