@@ -22,6 +22,7 @@ import {
22
22
} from './effect'
23
23
import { isReactive , isShallow } from './reactive'
24
24
import { type Ref , isRef } from './ref'
25
+ import { type SchedulerJob , SchedulerJobFlags } from './scheduler'
25
26
26
27
// These errors were transferred from `packages/runtime-core/src/errorHandling.ts`
27
28
// along with baseWatch to maintain code compatibility. Hence,
@@ -32,39 +33,6 @@ export enum BaseWatchErrorCodes {
32
33
WATCH_CLEANUP ,
33
34
}
34
35
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
-
68
36
type WatchEffect = ( onCleanup : OnCleanup ) => void
69
37
type WatchSource < T = any > = Ref < T > | ComputedRef < T > | ( ( ) => T )
70
38
type WatchCallback < V = any , OV = any > = (
@@ -78,15 +46,15 @@ export interface BaseWatchOptions<Immediate = boolean> extends DebuggerOptions {
78
46
immediate ?: Immediate
79
47
deep ?: boolean
80
48
once ?: boolean
81
- scheduler ?: Scheduler
49
+ scheduler ?: WatchScheduler
82
50
onError ?: HandleError
83
51
onWarn ?: HandleWarn
84
52
}
85
53
86
54
// initial value for watchers to trigger on undefined initial values
87
55
const INITIAL_WATCHER_VALUE = { }
88
56
89
- export type Scheduler = (
57
+ export type WatchScheduler = (
90
58
job : SchedulerJob ,
91
59
effect : ReactiveEffect ,
92
60
immediateFirstRun : boolean ,
@@ -95,7 +63,7 @@ export type Scheduler = (
95
63
export type HandleError = ( err : unknown , type : BaseWatchErrorCodes ) => void
96
64
export type HandleWarn = ( msg : string , ...args : any [ ] ) => void
97
65
98
- const DEFAULT_SCHEDULER : Scheduler = (
66
+ const DEFAULT_SCHEDULER : WatchScheduler = (
99
67
job ,
100
68
effect ,
101
69
immediateFirstRun ,
0 commit comments