mirror of https://github.com/vuejs/core.git
refactor(watch): reuse watch types
This commit is contained in:
parent
7dbab278d5
commit
f2ea25dc54
|
|
@ -90,4 +90,8 @@ export {
|
|||
type WatchScheduler,
|
||||
type WatchStopHandle,
|
||||
type WatchHandle,
|
||||
type WatchEffect,
|
||||
type WatchSource,
|
||||
type WatchCallback,
|
||||
type OnCleanup,
|
||||
} from './watch'
|
||||
|
|
|
|||
|
|
@ -34,14 +34,17 @@ export enum WatchErrorCodes {
|
|||
WATCH_CLEANUP,
|
||||
}
|
||||
|
||||
type WatchEffect = (onCleanup: OnCleanup) => void
|
||||
type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
|
||||
type WatchCallback<V = any, OV = any> = (
|
||||
export type WatchEffect = (onCleanup: OnCleanup) => void
|
||||
|
||||
export type WatchSource<T = any> = Ref<T, any> | ComputedRef<T> | (() => T)
|
||||
|
||||
export type WatchCallback<V = any, OV = any> = (
|
||||
value: V,
|
||||
oldValue: OV,
|
||||
onCleanup: OnCleanup,
|
||||
) => any
|
||||
type OnCleanup = (cleanupFn: () => void) => void
|
||||
|
||||
export type OnCleanup = (cleanupFn: () => void) => void
|
||||
|
||||
export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
|
||||
immediate?: Immediate
|
||||
|
|
|
|||
|
|
@ -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<T = any> = Ref<T, any> | ComputedRef<T> | (() => T)
|
||||
|
||||
export type WatchCallback<V = any, OV = any> = (
|
||||
value: V,
|
||||
oldValue: OV,
|
||||
onCleanup: OnCleanup,
|
||||
) => any
|
||||
export type {
|
||||
WatchHandle,
|
||||
WatchStopHandle,
|
||||
WatchEffect,
|
||||
WatchSource,
|
||||
WatchCallback,
|
||||
OnCleanup,
|
||||
} from '@vue/reactivity'
|
||||
|
||||
type MaybeUndefined<T, I> = I extends true ? T | undefined : T
|
||||
|
||||
|
|
@ -43,13 +41,11 @@ type MapSources<T, Immediate> = {
|
|||
: never
|
||||
}
|
||||
|
||||
export type OnCleanup = (cleanupFn: () => void) => void
|
||||
|
||||
export interface WatchOptionsBase extends DebuggerOptions {
|
||||
export interface WatchEffectOptions extends DebuggerOptions {
|
||||
flush?: 'pre' | 'post' | 'sync'
|
||||
}
|
||||
|
||||
export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
|
||||
export interface WatchOptions<Immediate = boolean> extends WatchEffectOptions {
|
||||
immediate?: Immediate
|
||||
deep?: boolean | number
|
||||
once?: boolean
|
||||
|
|
@ -58,7 +54,7 @@ export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
|
|||
// Simple effect.
|
||||
export function watchEffect(
|
||||
effect: WatchEffect,
|
||||
options?: WatchOptionsBase,
|
||||
options?: WatchEffectOptions,
|
||||
): WatchHandle {
|
||||
return doWatch(effect, null, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ export type {
|
|||
MultiWatchSources,
|
||||
WatchEffect,
|
||||
WatchOptions,
|
||||
WatchOptionsBase,
|
||||
WatchEffectOptions as WatchOptionsBase,
|
||||
WatchCallback,
|
||||
WatchSource,
|
||||
WatchHandle,
|
||||
|
|
|
|||
Loading…
Reference in New Issue