@@ -10,6 +10,7 @@ setComputedScheduler(queueJob)
10
10
export interface SchedulerJob extends Function {
11
11
id ?: number
12
12
active ?: boolean
13
+ computed ?: boolean
13
14
/**
14
15
* Indicates whether the effect is allowed to recursively trigger itself
15
16
* when managed by the scheduler.
@@ -70,16 +71,15 @@ export function nextTick<T = void>(
70
71
// Use binary-search to find a suitable position in the queue,
71
72
// so that the queue maintains the increasing order of job's id,
72
73
// which can prevent the job from being skipped and also can avoid repeated patching.
73
- function findInsertionIndex ( job : SchedulerJob ) {
74
+ function findInsertionIndex ( id : number ) {
74
75
// the start index should be `flushIndex + 1`
75
76
let start = flushIndex + 1
76
77
let end = queue . length
77
- const jobId = getId ( job )
78
78
79
79
while ( start < end ) {
80
80
const middle = ( start + end ) >>> 1
81
81
const middleJobId = getId ( queue [ middle ] )
82
- middleJobId < jobId ? ( start = middle + 1 ) : ( end = middle )
82
+ middleJobId < id ? ( start = middle + 1 ) : ( end = middle )
83
83
}
84
84
85
85
return start
@@ -100,11 +100,10 @@ export function queueJob(job: SchedulerJob) {
100
100
) ) &&
101
101
job !== currentPreFlushParentJob
102
102
) {
103
- const pos = findInsertionIndex ( job )
104
- if ( pos > - 1 ) {
105
- queue . splice ( pos , 0 , job )
106
- } else {
103
+ if ( job . id == null ) {
107
104
queue . push ( job )
105
+ } else {
106
+ queue . splice ( findInsertionIndex ( job . id ) , 0 , job )
108
107
}
109
108
queueFlush ( )
110
109
}
@@ -253,6 +252,7 @@ function flushJobs(seen?: CountMap) {
253
252
if ( __DEV__ && checkRecursiveUpdates ( seen ! , job ) ) {
254
253
continue
255
254
}
255
+ // console.log(`running:`, job.id)
256
256
callWithErrorHandling ( job , null , ErrorCodes . SCHEDULER )
257
257
}
258
258
}
0 commit comments