From fe9da2d0e4f9b338252b1b62941ee9ead71f0346 Mon Sep 17 00:00:00 2001 From: Yang Mingshan Date: Tue, 11 Feb 2020 20:30:25 +0800 Subject: [PATCH] fix(runtime-core/scheduler): invalidate job (#717) --- packages/runtime-core/__tests__/scheduler.spec.ts | 12 ++++++++++-- packages/runtime-core/src/scheduler.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/__tests__/scheduler.spec.ts b/packages/runtime-core/__tests__/scheduler.spec.ts index 65535d679a0..cf035c97a0d 100644 --- a/packages/runtime-core/__tests__/scheduler.spec.ts +++ b/packages/runtime-core/__tests__/scheduler.spec.ts @@ -246,12 +246,20 @@ describe('scheduler', () => { const job2 = () => { calls.push('job2') } - // queue both jobs + const job3 = () => { + calls.push('job3') + } + const job4 = () => { + calls.push('job4') + } + // queue all jobs queueJob(job1) queueJob(job2) + queueJob(job3) + queuePostFlushCb(job4) expect(calls).toEqual([]) await nextTick() // job2 should be called only once - expect(calls).toEqual(['job1', 'job2']) + expect(calls).toEqual(['job1', 'job2', 'job3', 'job4']) }) }) diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index a13a01280e0..c730730f416 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -70,7 +70,7 @@ function flushJobs(seen?: CountMap) { if (__DEV__) { seen = seen || new Map() } - while ((job = queue.shift())) { + while ((job = queue.shift()) !== undefined) { if (job === null) { continue }