Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions packages/reactivity/src/baseWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export enum BaseWatchErrorCodes {
// TODO move to a scheduler package
export interface SchedulerJob extends Function {
id?: number
// TODO refactor these boolean flags to a single bitwise flag
pre?: boolean
active?: boolean
computed?: boolean
queued?: boolean
/**
* Indicates whether the effect is allowed to recursively trigger itself
* when managed by the scheduler.
Expand Down
31 changes: 16 additions & 15 deletions packages/runtime-vapor/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,31 @@ const resolvedPromise = /*#__PURE__*/ Promise.resolve() as Promise<any>
let currentFlushPromise: Promise<void> | null = null

function queueJob(job: SchedulerJob) {
if (
!queue.length ||
!queue.includes(
job,
isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex,
)
) {
if (!job.queued) {
if (job.id == null) {
queue.push(job)
} else {
queue.splice(findInsertionIndex(job.id), 0, job)
// fast path when the job id is larger than the tail
if (!job.pre && job.id >= (queue[queue.length - 1]?.id || 0)) {
queue.push(job)
} else {
queue.splice(findInsertionIndex(job.id), 0, job)
}
}
if (!job.allowRecurse) {
job.queued = true
}
queueFlush()
}
}

export function queuePostRenderEffect(cb: SchedulerJobs) {
if (!isArray(cb)) {
if (
!activePostFlushCbs ||
!activePostFlushCbs.includes(
cb,
cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex,
)
) {
if (!cb.queued) {
pendingPostFlushCbs.push(cb)
if (!cb.allowRecurse) {
cb.queued = true
}
}
} else {
// if cb is an array, it is a component lifecycle hook which can only be
Expand Down Expand Up @@ -93,6 +92,7 @@ function flushPostFlushCbs() {
postFlushIndex++
) {
activePostFlushCbs[postFlushIndex]()
activePostFlushCbs[postFlushIndex].queued = false
}
activePostFlushCbs = null
postFlushIndex = 0
Expand All @@ -115,6 +115,7 @@ function flushJobs() {
try {
for (let i = 0; i < queue!.length; i++) {
queue![i]()
queue![i].queued = false
}
} finally {
flushIndex = 0
Expand Down