From 539a4fe78626719de20e07455e6b51bf1f816e5e Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 16 Dec 2020 22:15:00 +0800 Subject: [PATCH] fix(runtime-core): schedulerJob skip correctly fix(runtime-core): schedulerJob allow to skip avoid component double update fix(runtime-core): schedulerJob allow to skip avoid component double update fix: improve test: modify test case --- packages/runtime-core/__tests__/scheduler.spec.ts | 9 +++++++-- packages/runtime-core/src/scheduler.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/__tests__/scheduler.spec.ts b/packages/runtime-core/__tests__/scheduler.spec.ts index 39f4de981a4..58f6856161a 100644 --- a/packages/runtime-core/__tests__/scheduler.spec.ts +++ b/packages/runtime-core/__tests__/scheduler.spec.ts @@ -373,19 +373,24 @@ describe('scheduler', () => { } const job3 = () => { calls.push('job3') + invalidateJob(job1) } const job4 = () => { calls.push('job4') } + const job5 = () => { + calls.push('job5') + } // queue all jobs queueJob(job1) queueJob(job2) queueJob(job3) - queuePostFlushCb(job4) + queueJob(job4) + queuePostFlushCb(job5) expect(calls).toEqual([]) await nextTick() // job2 should be called only once - expect(calls).toEqual(['job1', 'job2', 'job3', 'job4']) + expect(calls).toEqual(['job1', 'job2', 'job3', 'job4', 'job5']) }) test('sort job based on id', async () => { diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index e2781f97e4d..aac1a5ca716 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -86,7 +86,7 @@ function queueFlush() { export function invalidateJob(job: SchedulerJob) { const i = queue.indexOf(job) - if (i > -1) { + if (i > flushIndex) { queue.splice(i, 1) } }