@@ -22,6 +22,7 @@ import {
2222} from './effect'
2323import { isReactive , isShallow } from './reactive'
2424import { type Ref , isRef } from './ref'
25+ import { type SchedulerJob , SchedulerJobFlags } from './scheduler'
2526
2627// These errors were transferred from `packages/runtime-core/src/errorHandling.ts`
2728// along with baseWatch to maintain code compatibility. Hence,
@@ -32,39 +33,6 @@ export enum BaseWatchErrorCodes {
3233 WATCH_CLEANUP ,
3334}
3435
35- // TODO move to a scheduler package
36- enum SchedulerJobFlags {
37- QUEUED = 1 << 0 ,
38- PRE = 1 << 1 ,
39- /**
40- * Indicates whether the effect is allowed to recursively trigger itself
41- * when managed by the scheduler.
42- *
43- * By default, a job cannot trigger itself because some built-in method calls,
44- * e.g. Array.prototype.push actually performs reads as well (#1740) which
45- * can lead to confusing infinite loops.
46- * The allowed cases are component update functions and watch callbacks.
47- * Component update functions may update child component props, which in turn
48- * trigger flush: "pre" watch callbacks that mutates state that the parent
49- * relies on (#1801). Watch callbacks doesn't track its dependencies so if it
50- * triggers itself again, it's likely intentional and it is the user's
51- * responsibility to perform recursive state mutation that eventually
52- * stabilizes (#1727).
53- */
54- ALLOW_RECURSE = 1 << 2 ,
55- DISPOSED = 1 << 3 ,
56- }
57-
58- // TODO move to a scheduler package
59- export interface SchedulerJob extends Function {
60- id ?: number
61- /**
62- * flags can technically be undefined, but it can still be used in bitwise
63- * operations just like 0.
64- */
65- flags ?: SchedulerJobFlags
66- }
67-
6836type WatchEffect = ( onCleanup : OnCleanup ) => void
6937type WatchSource < T = any > = Ref < T > | ComputedRef < T > | ( ( ) => T )
7038type WatchCallback < V = any , OV = any > = (
@@ -78,15 +46,15 @@ export interface BaseWatchOptions<Immediate = boolean> extends DebuggerOptions {
7846 immediate ?: Immediate
7947 deep ?: boolean
8048 once ?: boolean
81- scheduler ?: Scheduler
49+ scheduler ?: WatchScheduler
8250 onError ?: HandleError
8351 onWarn ?: HandleWarn
8452}
8553
8654// initial value for watchers to trigger on undefined initial values
8755const INITIAL_WATCHER_VALUE = { }
8856
89- export type Scheduler = (
57+ export type WatchScheduler = (
9058 job : SchedulerJob ,
9159 effect : ReactiveEffect ,
9260 immediateFirstRun : boolean ,
@@ -95,7 +63,7 @@ export type Scheduler = (
9563export type HandleError = ( err : unknown , type : BaseWatchErrorCodes ) => void
9664export type HandleWarn = ( msg : string , ...args : any [ ] ) => void
9765
98- const DEFAULT_SCHEDULER : Scheduler = (
66+ const DEFAULT_SCHEDULER : WatchScheduler = (
9967 job ,
10068 effect ,
10169 immediateFirstRun ,
0 commit comments