fix(scheduler): sort jobs before flushing

This fixes the case where a child component is added to the queue before
its parent, but should be invalidated by its parent's update. Same logic
was present in Vue 2.

Properly fixes #910
ref: https://github.com/vuejs/vue-next/issues/910#issuecomment-613097539
This commit is contained in:
Evan You
2020-04-14 17:31:35 -04:00
parent c80b857eb5
commit 78977c3997
3 changed files with 46 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ const targetMap = new WeakMap<any, KeyToDepMap>()
export interface ReactiveEffect<T = any> {
(...args: any[]): T
_isEffect: true
id: number
active: boolean
raw: () => T
deps: Array<Dep>
@@ -21,7 +22,7 @@ export interface ReactiveEffect<T = any> {
export interface ReactiveEffectOptions {
lazy?: boolean
computed?: boolean
scheduler?: (job: () => void) => void
scheduler?: (job: ReactiveEffect) => void
onTrack?: (event: DebuggerEvent) => void
onTrigger?: (event: DebuggerEvent) => void
onStop?: () => void
@@ -74,6 +75,8 @@ export function stop(effect: ReactiveEffect) {
}
}
let uid = 0
function createReactiveEffect<T = any>(
fn: (...args: any[]) => T,
options: ReactiveEffectOptions
@@ -96,6 +99,7 @@ function createReactiveEffect<T = any>(
}
}
} as ReactiveEffect
effect.id = uid++
effect._isEffect = true
effect.active = true
effect.raw = fn