Skip to content

Commit

Permalink
fix(runtime-core): schedulerJob skip correctly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edison1105 committed Feb 5, 2021
1 parent 07559e5 commit 539a4fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/runtime-core/__tests__/scheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 539a4fe

Please sign in to comment.