@@ -40,11 +40,8 @@ export interface SchedulerJob extends Function {
40
40
41
41
export type SchedulerJobs = SchedulerJob | SchedulerJob [ ]
42
42
43
- let isFlushing = false
44
- let isFlushPending = false
45
-
46
43
const queue : SchedulerJob [ ] = [ ]
47
- let flushIndex = 0
44
+ let flushIndex = - 1
48
45
49
46
const pendingPostFlushCbs : SchedulerJob [ ] = [ ]
50
47
let activePostFlushCbs : SchedulerJob [ ] | null = null
@@ -74,7 +71,7 @@ export function nextTick<T = void, R = void>(
74
71
// watcher should be inserted immediately before the update job. This allows
75
72
// watchers to be skipped if the component is unmounted by the parent update.
76
73
function findInsertionIndex ( id : number ) {
77
- let start = isFlushing ? flushIndex + 1 : 0
74
+ let start = flushIndex + 1
78
75
let end = queue . length
79
76
80
77
while ( start < end ) {
@@ -115,8 +112,7 @@ export function queueJob(job: SchedulerJob): void {
115
112
}
116
113
117
114
function queueFlush ( ) {
118
- if ( ! isFlushing && ! isFlushPending ) {
119
- isFlushPending = true
115
+ if ( ! currentFlushPromise ) {
120
116
currentFlushPromise = resolvedPromise . then ( flushJobs )
121
117
}
122
118
}
@@ -141,8 +137,8 @@ export function queuePostFlushCb(cb: SchedulerJobs): void {
141
137
export function flushPreFlushCbs (
142
138
instance ?: ComponentInternalInstance ,
143
139
seen ?: CountMap ,
144
- // if currently flushing, skip the current job itself
145
- i : number = isFlushing ? flushIndex + 1 : 0 ,
140
+ // skip the current job
141
+ i : number = flushIndex + 1 ,
146
142
) : void {
147
143
if ( __DEV__ ) {
148
144
seen = seen || new Map ( )
@@ -211,8 +207,6 @@ const getId = (job: SchedulerJob): number =>
211
207
job . id == null ? ( job . flags ! & SchedulerJobFlags . PRE ? - 1 : Infinity ) : job . id
212
208
213
209
function flushJobs ( seen ?: CountMap ) {
214
- isFlushPending = false
215
- isFlushing = true
216
210
if ( __DEV__ ) {
217
211
seen = seen || new Map ( )
218
212
}
@@ -255,15 +249,13 @@ function flushJobs(seen?: CountMap) {
255
249
}
256
250
}
257
251
258
- flushIndex = 0
252
+ flushIndex = - 1
259
253
queue . length = 0
260
254
261
255
flushPostFlushCbs ( seen )
262
256
263
- isFlushing = false
264
257
currentFlushPromise = null
265
- // some postFlushCb queued jobs!
266
- // keep flushing until it drains.
258
+ // If new jobs have been added to either queue, keep flushing
267
259
if ( queue . length || pendingPostFlushCbs . length ) {
268
260
flushJobs ( seen )
269
261
}
0 commit comments