From: Evan You Date: Tue, 20 Aug 2024 08:15:08 +0000 (+0800) Subject: refactor(watch): reuse watch types X-Git-Tag: v3.5.0-rc.1~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2ea25dc5493b9baaefd7fe6caed1d76765b2fe4;p=thirdparty%2Fvuejs%2Fcore.git refactor(watch): reuse watch types --- diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index 47302b224d..f0445e87da 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -90,4 +90,8 @@ export { type WatchScheduler, type WatchStopHandle, type WatchHandle, + type WatchEffect, + type WatchSource, + type WatchCallback, + type OnCleanup, } from './watch' diff --git a/packages/reactivity/src/watch.ts b/packages/reactivity/src/watch.ts index 2104896b7a..96da5ffe5c 100644 --- a/packages/reactivity/src/watch.ts +++ b/packages/reactivity/src/watch.ts @@ -34,14 +34,17 @@ export enum WatchErrorCodes { WATCH_CLEANUP, } -type WatchEffect = (onCleanup: OnCleanup) => void -type WatchSource = Ref | ComputedRef | (() => T) -type WatchCallback = ( +export type WatchEffect = (onCleanup: OnCleanup) => void + +export type WatchSource = Ref | ComputedRef | (() => T) + +export type WatchCallback = ( value: V, oldValue: OV, onCleanup: OnCleanup, ) => any -type OnCleanup = (cleanupFn: () => void) => void + +export type OnCleanup = (cleanupFn: () => void) => void export interface WatchOptions extends DebuggerOptions { immediate?: Immediate diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 3304f2c75b..a14823beb6 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -1,10 +1,11 @@ import { type WatchOptions as BaseWatchOptions, - type ComputedRef, type DebuggerOptions, type ReactiveMarker, - type Ref, + type WatchCallback, + type WatchEffect, type WatchHandle, + type WatchSource, watch as baseWatch, } from '@vue/reactivity' import { type SchedulerJob, SchedulerJobFlags, queueJob } from './scheduler' @@ -21,17 +22,14 @@ import { warn } from './warning' import type { ObjectWatchOptionItem } from './componentOptions' import { useSSRContext } from './helpers/useSsrContext' -export type { WatchHandle, WatchStopHandle } from '@vue/reactivity' - -export type WatchEffect = (onCleanup: OnCleanup) => void - -export type WatchSource = Ref | ComputedRef | (() => T) - -export type WatchCallback = ( - value: V, - oldValue: OV, - onCleanup: OnCleanup, -) => any +export type { + WatchHandle, + WatchStopHandle, + WatchEffect, + WatchSource, + WatchCallback, + OnCleanup, +} from '@vue/reactivity' type MaybeUndefined = I extends true ? T | undefined : T @@ -43,13 +41,11 @@ type MapSources = { : never } -export type OnCleanup = (cleanupFn: () => void) => void - -export interface WatchOptionsBase extends DebuggerOptions { +export interface WatchEffectOptions extends DebuggerOptions { flush?: 'pre' | 'post' | 'sync' } -export interface WatchOptions extends WatchOptionsBase { +export interface WatchOptions extends WatchEffectOptions { immediate?: Immediate deep?: boolean | number once?: boolean @@ -58,7 +54,7 @@ export interface WatchOptions extends WatchOptionsBase { // Simple effect. export function watchEffect( effect: WatchEffect, - options?: WatchOptionsBase, + options?: WatchEffectOptions, ): WatchHandle { return doWatch(effect, null, options) } diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 68a6aac902..7f716b5f4e 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -229,7 +229,7 @@ export type { MultiWatchSources, WatchEffect, WatchOptions, - WatchOptionsBase, + WatchEffectOptions as WatchOptionsBase, WatchCallback, WatchSource, WatchHandle,