From ce49fdf999967e838fe6b61373c00cb61ff87f33 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 12 Jan 2022 22:07:47 +0800 Subject: [PATCH] refactor: more readable type names for watch cleanup function --- packages/runtime-core/src/apiWatch.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 092491d3..b26c3ee2 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -40,14 +40,14 @@ import { DeprecationTypes } from './compat/compatConfig' import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig' import { ObjectWatchOptionItem } from './componentOptions' -export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void +export type WatchEffect = (onCleanup: OnCleanup) => void export type WatchSource = Ref | ComputedRef | (() => T) export type WatchCallback = ( value: V, oldValue: OV, - onInvalidate: InvalidateCbRegistrator + onCleanup: OnCleanup ) => any type MapSources = { @@ -62,7 +62,7 @@ type MapSources = { : never } -type InvalidateCbRegistrator = (cb: () => void) => void +type OnCleanup = (cleanupFn: () => void) => void export interface WatchOptionsBase extends DebuggerOptions { flush?: 'pre' | 'post' | 'sync' @@ -242,7 +242,7 @@ function doWatch( source, instance, ErrorCodes.WATCH_CALLBACK, - [onInvalidate] + [onCleanup] ) } } @@ -272,7 +272,7 @@ function doWatch( } let cleanup: () => void - let onInvalidate: InvalidateCbRegistrator = (fn: () => void) => { + let onCleanup: OnCleanup = (fn: () => void) => { cleanup = effect.onStop = () => { callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP) } @@ -282,14 +282,14 @@ function doWatch( // unless it's eager if (__SSR__ && isInSSRComponentSetup) { // we will also not call the invalidate callback (+ runner is not set up) - onInvalidate = NOOP + onCleanup = NOOP if (!cb) { getter() } else if (immediate) { callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [ getter(), isMultiSource ? [] : undefined, - onInvalidate + onCleanup ]) } return NOOP @@ -323,7 +323,7 @@ function doWatch( newValue, // pass undefined as the old value when it's changed for the first time oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, - onInvalidate + onCleanup ]) oldValue = newValue }