Skip to content

Commit f2ea25d

Browse files
committed
refactor(watch): reuse watch types
1 parent 7dbab27 commit f2ea25d

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

packages/reactivity/src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ export {
9090
type WatchScheduler,
9191
type WatchStopHandle,
9292
type WatchHandle,
93+
type WatchEffect,
94+
type WatchSource,
95+
type WatchCallback,
96+
type OnCleanup,
9397
} from './watch'

packages/reactivity/src/watch.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ export enum WatchErrorCodes {
3434
WATCH_CLEANUP,
3535
}
3636

37-
type WatchEffect = (onCleanup: OnCleanup) => void
38-
type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
39-
type WatchCallback<V = any, OV = any> = (
37+
export type WatchEffect = (onCleanup: OnCleanup) => void
38+
39+
export type WatchSource<T = any> = Ref<T, any> | ComputedRef<T> | (() => T)
40+
41+
export type WatchCallback<V = any, OV = any> = (
4042
value: V,
4143
oldValue: OV,
4244
onCleanup: OnCleanup,
4345
) => any
44-
type OnCleanup = (cleanupFn: () => void) => void
46+
47+
export type OnCleanup = (cleanupFn: () => void) => void
4548

4649
export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
4750
immediate?: Immediate

packages/runtime-core/src/apiWatch.ts

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {
22
type WatchOptions as BaseWatchOptions,
3-
type ComputedRef,
43
type DebuggerOptions,
54
type ReactiveMarker,
6-
type Ref,
5+
type WatchCallback,
6+
type WatchEffect,
77
type WatchHandle,
8+
type WatchSource,
89
watch as baseWatch,
910
} from '@vue/reactivity'
1011
import { type SchedulerJob, SchedulerJobFlags, queueJob } from './scheduler'
@@ -21,17 +22,14 @@ import { warn } from './warning'
2122
import type { ObjectWatchOptionItem } from './componentOptions'
2223
import { useSSRContext } from './helpers/useSsrContext'
2324

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'
3533

3634
type MaybeUndefined<T, I> = I extends true ? T | undefined : T
3735

@@ -43,13 +41,11 @@ type MapSources<T, Immediate> = {
4341
: never
4442
}
4543

46-
export type OnCleanup = (cleanupFn: () => void) => void
47-
48-
export interface WatchOptionsBase extends DebuggerOptions {
44+
export interface WatchEffectOptions extends DebuggerOptions {
4945
flush?: 'pre' | 'post' | 'sync'
5046
}
5147

52-
export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
48+
export interface WatchOptions<Immediate = boolean> extends WatchEffectOptions {
5349
immediate?: Immediate
5450
deep?: boolean | number
5551
once?: boolean
@@ -58,7 +54,7 @@ export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
5854
// Simple effect.
5955
export function watchEffect(
6056
effect: WatchEffect,
61-
options?: WatchOptionsBase,
57+
options?: WatchEffectOptions,
6258
): WatchHandle {
6359
return doWatch(effect, null, options)
6460
}

packages/runtime-core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export type {
229229
MultiWatchSources,
230230
WatchEffect,
231231
WatchOptions,
232-
WatchOptionsBase,
232+
WatchEffectOptions as WatchOptionsBase,
233233
WatchCallback,
234234
WatchSource,
235235
WatchHandle,

0 commit comments

Comments
 (0)