File tree 4 files changed +50
-6
lines changed
4 files changed +50
-6
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,8 @@ export function lifecycleMixin (Vue: Class<Component>) {
109
109
if ( vm . $vnode && vm . $parent && vm . $vnode === vm . $parent . _vnode ) {
110
110
vm . $parent . $el = vm . $el
111
111
}
112
- if ( vm . _isMounted ) {
113
- callHook ( vm , 'updated' )
114
- }
112
+ // updated hook is called by the scheduler to ensure that children are
113
+ // updated in a parent's updated hook.
115
114
}
116
115
117
116
Vue . prototype . _updateFromParent = function (
Original file line number Diff line number Diff line change 2
2
3
3
import type Watcher from './watcher'
4
4
import config from '../config'
5
+ import { callHook } from '../instance/lifecycle'
5
6
import {
6
7
warn ,
7
8
nextTick ,
@@ -32,6 +33,7 @@ function resetSchedulerState () {
32
33
*/
33
34
function flushSchedulerQueue ( ) {
34
35
flushing = true
36
+ let watcher , id , vm
35
37
36
38
// Sort queue before flush.
37
39
// This ensures that:
@@ -46,8 +48,8 @@ function flushSchedulerQueue () {
46
48
// do not cache length because more watchers might be pushed
47
49
// as we run existing watchers
48
50
for ( index = 0 ; index < queue . length ; index ++ ) {
49
- const watcher = queue [ index ]
50
- const id = watcher . id
51
+ watcher = queue [ index ]
52
+ id = watcher . id
51
53
has [ id ] = null
52
54
watcher . run ( )
53
55
// in dev build, check and stop circular updates.
@@ -67,6 +69,16 @@ function flushSchedulerQueue () {
67
69
}
68
70
}
69
71
72
+ // call updated hooks
73
+ index = queue . length
74
+ while ( index -- ) {
75
+ watcher = queue [ index ]
76
+ vm = watcher . vm
77
+ if ( vm . _watcher === watcher && vm . _isMounted ) {
78
+ callHook ( vm , 'updated' )
79
+ }
80
+ }
81
+
70
82
// devtool hook
71
83
/* istanbul ignore if */
72
84
if ( devtools && config . devtools ) {
Original file line number Diff line number Diff line change @@ -156,6 +156,34 @@ describe('Options lifecyce hooks', () => {
156
156
expect ( spy ) . toHaveBeenCalled ( )
157
157
} ) . then ( done )
158
158
} )
159
+
160
+ it ( 'should be called after children are updated' , done => {
161
+ const calls = [ ]
162
+ const vm = new Vue ( {
163
+ template : '<div><test ref="child">{{ msg }}</test></div>' ,
164
+ data : { msg : 'foo' } ,
165
+ components : {
166
+ test : {
167
+ template : `<div><slot></slot></div>` ,
168
+ updated ( ) {
169
+ expect ( this . $el . textContent ) . toBe ( 'bar' )
170
+ calls . push ( 'child' )
171
+ }
172
+ }
173
+ } ,
174
+ updated ( ) {
175
+ expect ( this . $el . textContent ) . toBe ( 'bar' )
176
+ calls . push ( 'parent' )
177
+ }
178
+ } ) . $mount ( )
179
+
180
+ expect ( calls ) . toEqual ( [ ] )
181
+ vm . msg = 'bar'
182
+ expect ( calls ) . toEqual ( [ ] )
183
+ waitForUpdate ( ( ) => {
184
+ expect ( calls ) . toEqual ( [ 'child' , 'parent' ] )
185
+ } ) . then ( done )
186
+ } )
159
187
} )
160
188
161
189
describe ( 'beforeDestroy' , ( ) => {
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
2
import config from 'core/config'
3
- import { queueWatcher } from 'core/observer/scheduler'
3
+ import { queueWatcher as _queueWatcher } from 'core/observer/scheduler'
4
+
5
+ function queueWatcher ( watcher ) {
6
+ watcher . vm = { } // mock vm
7
+ _queueWatcher ( watcher )
8
+ }
4
9
5
10
describe ( 'Scheduler' , ( ) => {
6
11
let spy
You can’t perform that action at this time.
0 commit comments