File tree 2 files changed +37
-1
lines changed
test/unit/modules/observer
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import type { Component } from 'types/component'
8
8
9
9
export const MAX_UPDATE_COUNT = 100
10
10
11
- const queue : Array < Watcher > = [ ]
11
+ let queue : Array < Watcher > = [ ]
12
12
const activatedChildren : Array < Component > = [ ]
13
13
let has : { [ key : number ] : true | undefined | null } = { }
14
14
let circular : { [ key : number ] : number } = { }
@@ -96,6 +96,12 @@ function flushSchedulerQueue() {
96
96
id = watcher . id
97
97
has [ id ] = null
98
98
watcher . run ( )
99
+ //when flushing,new watchers will be added to the queue and they should be resort
100
+ queue = [
101
+ ...queue . slice ( 0 , index + 1 ) ,
102
+ ...queue . slice ( index + 1 ) . sort ( sortCompareFn )
103
+ ]
104
+
99
105
// in dev build, check and stop circular updates.
100
106
if ( __DEV__ && has [ id ] != null ) {
101
107
circular [ id ] = ( circular [ id ] || 0 ) + 1
Original file line number Diff line number Diff line change @@ -151,6 +151,36 @@ describe('Scheduler', () => {
151
151
} ) . then ( done )
152
152
} )
153
153
154
+ // Github issue #12897
155
+ it ( 'should call newly pushed watcher orderly via the flush attribute after current watcher is done' , done => {
156
+ const callOrder : any [ ] = [ ]
157
+ queueWatcher ( {
158
+ id : 1 ,
159
+ user : true ,
160
+ run ( ) {
161
+ callOrder . push ( 1 )
162
+
163
+ queueWatcher ( {
164
+ id : 3 ,
165
+ run ( ) {
166
+ callOrder . push ( 4 )
167
+ } ,
168
+ post : true
169
+ } )
170
+ queueWatcher ( {
171
+ id : 4 ,
172
+ run ( ) {
173
+ callOrder . push ( 3 )
174
+ }
175
+ } ) ,
176
+ callOrder . push ( 2 )
177
+ }
178
+ } )
179
+ waitForUpdate ( ( ) => {
180
+ expect ( callOrder ) . toEqual ( [ 1 , 2 , 3 , 4 ] )
181
+ } ) . then ( done )
182
+ } )
183
+
154
184
// GitHub issue #5191
155
185
it ( 'emit should work when updated hook called' , done => {
156
186
const el = document . createElement ( 'div' )
You can’t perform that action at this time.
0 commit comments