]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(watch): reuse watch types
authorEvan You <evan@vuejs.org>
Tue, 20 Aug 2024 08:15:08 +0000 (16:15 +0800)
committerEvan You <evan@vuejs.org>
Tue, 20 Aug 2024 08:16:25 +0000 (16:16 +0800)
packages/reactivity/src/index.ts
packages/reactivity/src/watch.ts
packages/runtime-core/src/apiWatch.ts
packages/runtime-core/src/index.ts

index 47302b224d73fada17c8055e8630eecf01f1f881..f0445e87da0dcc0538b2ad63a88822aa4cdd02bc 100644 (file)
@@ -90,4 +90,8 @@ export {
   type WatchScheduler,
   type WatchStopHandle,
   type WatchHandle,
+  type WatchEffect,
+  type WatchSource,
+  type WatchCallback,
+  type OnCleanup,
 } from './watch'
index 2104896b7ae34caaafb0ac1ac434354e0c0b9741..96da5ffe5c23e91a4171d9611ad43f11dde8ac76 100644 (file)
@@ -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
index 3304f2c75b618c147dc3734a44f9ef34881c53d1..a14823beb6256202eb2e35e21b1d66dd9b08c937 100644 (file)
@@ -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)
 }
index 68a6aac9027a539213ba5bd1293d682fa6b6043a..7f716b5f4e8e9a4d0522e238b4dd68786ae29eb7 100644 (file)
@@ -229,7 +229,7 @@ export type {
   MultiWatchSources,
   WatchEffect,
   WatchOptions,
-  WatchOptionsBase,
+  WatchEffectOptions as WatchOptionsBase,
   WatchCallback,
   WatchSource,
   WatchHandle,