From e42d6b0712af3c4aca407239b0aa31011aa92d82 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 26 Feb 2020 10:12:32 -0500 Subject: [PATCH] refactor: use consistent name for watch invalidation register function --- packages/runtime-core/src/apiWatch.ts | 14 +++++++------- packages/runtime-core/src/index.ts | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index eb322bd2f5..889821a72a 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -34,14 +34,14 @@ import { onBeforeUnmount } from './apiLifecycle' import { queuePostRenderEffect } from './renderer' import { warn } from './warning' -export type WatchEffect = (onCleanup: CleanupRegistrator) => void +export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void export type WatchSource = Ref | ComputedRef | (() => T) export type WatchCallback = ( value: V, oldValue: OV, - onCleanup: CleanupRegistrator + onInvalidate: InvalidateCbRegistrator ) => any type MapSources = { @@ -54,7 +54,7 @@ type MapOldSources = { : never } -export type CleanupRegistrator = (invalidate: () => void) => void +type InvalidateCbRegistrator = (cb: () => void) => void export interface BaseWatchOptions { flush?: 'pre' | 'post' | 'sync' @@ -169,7 +169,7 @@ function doWatch( source, instance, ErrorCodes.WATCH_CALLBACK, - [registerCleanup] + [onInvalidate] ) } } @@ -180,7 +180,7 @@ function doWatch( } let cleanup: Function - const registerCleanup: CleanupRegistrator = (fn: () => void) => { + const onInvalidate: InvalidateCbRegistrator = (fn: () => void) => { cleanup = runner.options.onStop = () => { callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP) } @@ -195,7 +195,7 @@ function doWatch( callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [ getter(), undefined, - registerCleanup + onInvalidate ]) } return NOOP @@ -217,7 +217,7 @@ function doWatch( newValue, // pass undefined as the old value when it's changed for the first time oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, - registerCleanup + onInvalidate ]) oldValue = newValue } diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 634d53b424..4e9459d4af 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -152,7 +152,6 @@ export { // types WatchOptions, WatchCallback, - CleanupRegistrator, WatchSource, StopHandle } from './apiWatch' -- 2.47.3