Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): refactor scheduler queue not be empty #2567

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type SchedulerCbs = SchedulerCb | SchedulerCb[]
let isFlushing = false
let isFlushPending = false

const queue: (SchedulerJob | null)[] = []
const queue: SchedulerJob[] = []
let flushIndex = 0

const pendingPreFlushCbs: SchedulerCb[] = []
Expand Down Expand Up @@ -87,7 +87,7 @@ function queueFlush() {
export function invalidateJob(job: SchedulerJob) {
const i = queue.indexOf(job)
if (i > -1) {
queue[i] = null
queue.splice(i, 1)
}
}

Expand Down Expand Up @@ -205,9 +205,7 @@ function flushJobs(seen?: CountMap) {
// priority number)
// 2. If a component is unmounted during a parent component's update,
// its update can be skipped.
// Jobs can never be null before flush starts, since they are only invalidated
// during execution of another flushed job.
queue.sort((a, b) => getId(a!) - getId(b!))
queue.sort((a, b) => getId(a) - getId(b))

try {
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
Expand Down