@@ -40,11 +40,8 @@ export interface SchedulerJob extends Function {
4040
4141export type SchedulerJobs = SchedulerJob | SchedulerJob [ ]
4242
43- let isFlushing = false
44- let isFlushPending = false
45-
4643const queue : SchedulerJob [ ] = [ ]
47- let flushIndex = 0
44+ let flushIndex = - 1
4845
4946const pendingPostFlushCbs : SchedulerJob [ ] = [ ]
5047let activePostFlushCbs : SchedulerJob [ ] | null = null
@@ -74,7 +71,7 @@ export function nextTick<T = void, R = void>(
7471// watcher should be inserted immediately before the update job. This allows
7572// watchers to be skipped if the component is unmounted by the parent update.
7673function findInsertionIndex ( id : number ) {
77- let start = isFlushing ? flushIndex + 1 : 0
74+ let start = flushIndex + 1
7875 let end = queue . length
7976
8077 while ( start < end ) {
@@ -115,8 +112,7 @@ export function queueJob(job: SchedulerJob): void {
115112}
116113
117114function queueFlush ( ) {
118- if ( ! isFlushing && ! isFlushPending ) {
119- isFlushPending = true
115+ if ( ! currentFlushPromise ) {
120116 currentFlushPromise = resolvedPromise . then ( flushJobs )
121117 }
122118}
@@ -141,8 +137,8 @@ export function queuePostFlushCb(cb: SchedulerJobs): void {
141137export function flushPreFlushCbs (
142138 instance ?: ComponentInternalInstance ,
143139 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 ,
146142) : void {
147143 if ( __DEV__ ) {
148144 seen = seen || new Map ( )
@@ -211,8 +207,6 @@ const getId = (job: SchedulerJob): number =>
211207 job . id == null ? ( job . flags ! & SchedulerJobFlags . PRE ? - 1 : Infinity ) : job . id
212208
213209function flushJobs ( seen ?: CountMap ) {
214- isFlushPending = false
215- isFlushing = true
216210 if ( __DEV__ ) {
217211 seen = seen || new Map ( )
218212 }
@@ -255,15 +249,13 @@ function flushJobs(seen?: CountMap) {
255249 }
256250 }
257251
258- flushIndex = 0
252+ flushIndex = - 1
259253 queue . length = 0
260254
261255 flushPostFlushCbs ( seen )
262256
263- isFlushing = false
264257 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
267259 if ( queue . length || pendingPostFlushCbs . length ) {
268260 flushJobs ( seen )
269261 }
0 commit comments