refactor: use consistent name for watch invalidation register function

This commit is contained in:
Evan You 2020-02-26 10:12:32 -05:00
parent 04f83fa681
commit e42d6b0712
2 changed files with 7 additions and 8 deletions

View File

@ -34,14 +34,14 @@ import { onBeforeUnmount } from './apiLifecycle'
import { queuePostRenderEffect } from './renderer' import { queuePostRenderEffect } from './renderer'
import { warn } from './warning' import { warn } from './warning'
export type WatchEffect = (onCleanup: CleanupRegistrator) => void export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void
export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T) export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
export type WatchCallback<V = any, OV = any> = ( export type WatchCallback<V = any, OV = any> = (
value: V, value: V,
oldValue: OV, oldValue: OV,
onCleanup: CleanupRegistrator onInvalidate: InvalidateCbRegistrator
) => any ) => any
type MapSources<T> = { type MapSources<T> = {
@ -54,7 +54,7 @@ type MapOldSources<T, Immediate> = {
: never : never
} }
export type CleanupRegistrator = (invalidate: () => void) => void type InvalidateCbRegistrator = (cb: () => void) => void
export interface BaseWatchOptions { export interface BaseWatchOptions {
flush?: 'pre' | 'post' | 'sync' flush?: 'pre' | 'post' | 'sync'
@ -169,7 +169,7 @@ function doWatch(
source, source,
instance, instance,
ErrorCodes.WATCH_CALLBACK, ErrorCodes.WATCH_CALLBACK,
[registerCleanup] [onInvalidate]
) )
} }
} }
@ -180,7 +180,7 @@ function doWatch(
} }
let cleanup: Function let cleanup: Function
const registerCleanup: CleanupRegistrator = (fn: () => void) => { const onInvalidate: InvalidateCbRegistrator = (fn: () => void) => {
cleanup = runner.options.onStop = () => { cleanup = runner.options.onStop = () => {
callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP) callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP)
} }
@ -195,7 +195,7 @@ function doWatch(
callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [ callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
getter(), getter(),
undefined, undefined,
registerCleanup onInvalidate
]) ])
} }
return NOOP return NOOP
@ -217,7 +217,7 @@ function doWatch(
newValue, newValue,
// pass undefined as the old value when it's changed for the first time // pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
registerCleanup onInvalidate
]) ])
oldValue = newValue oldValue = newValue
} }

View File

@ -152,7 +152,6 @@ export {
// types // types
WatchOptions, WatchOptions,
WatchCallback, WatchCallback,
CleanupRegistrator,
WatchSource, WatchSource,
StopHandle StopHandle
} from './apiWatch' } from './apiWatch'