1
1
import {
2
2
type WatchOptions as BaseWatchOptions ,
3
- type ComputedRef ,
4
3
type DebuggerOptions ,
5
4
type ReactiveMarker ,
6
- type Ref ,
5
+ type WatchCallback ,
6
+ type WatchEffect ,
7
7
type WatchHandle ,
8
+ type WatchSource ,
8
9
watch as baseWatch ,
9
10
} from '@vue/reactivity'
10
11
import { type SchedulerJob , SchedulerJobFlags , queueJob } from './scheduler'
@@ -21,17 +22,14 @@ import { warn } from './warning'
21
22
import type { ObjectWatchOptionItem } from './componentOptions'
22
23
import { useSSRContext } from './helpers/useSsrContext'
23
24
24
- export type { WatchHandle , WatchStopHandle } from '@vue/reactivity'
25
-
26
- export type WatchEffect = ( onCleanup : OnCleanup ) => void
27
-
28
- export type WatchSource < T = any > = Ref < T , any > | ComputedRef < T > | ( ( ) => T )
29
-
30
- export type WatchCallback < V = any , OV = any > = (
31
- value : V ,
32
- oldValue : OV ,
33
- onCleanup : OnCleanup ,
34
- ) => any
25
+ export type {
26
+ WatchHandle ,
27
+ WatchStopHandle ,
28
+ WatchEffect ,
29
+ WatchSource ,
30
+ WatchCallback ,
31
+ OnCleanup ,
32
+ } from '@vue/reactivity'
35
33
36
34
type MaybeUndefined < T , I > = I extends true ? T | undefined : T
37
35
@@ -43,13 +41,11 @@ type MapSources<T, Immediate> = {
43
41
: never
44
42
}
45
43
46
- export type OnCleanup = ( cleanupFn : ( ) => void ) => void
47
-
48
- export interface WatchOptionsBase extends DebuggerOptions {
44
+ export interface WatchEffectOptions extends DebuggerOptions {
49
45
flush ?: 'pre' | 'post' | 'sync'
50
46
}
51
47
52
- export interface WatchOptions < Immediate = boolean > extends WatchOptionsBase {
48
+ export interface WatchOptions < Immediate = boolean > extends WatchEffectOptions {
53
49
immediate ?: Immediate
54
50
deep ?: boolean | number
55
51
once ?: boolean
@@ -58,7 +54,7 @@ export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
58
54
// Simple effect.
59
55
export function watchEffect (
60
56
effect : WatchEffect ,
61
- options ?: WatchOptionsBase ,
57
+ options ?: WatchEffectOptions ,
62
58
) : WatchHandle {
63
59
return doWatch ( effect , null , options )
64
60
}
0 commit comments