Skip to content

Commit

Permalink
refactor: use consistent name for watch invalidation register function
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 26, 2020
1 parent 04f83fa commit e42d6b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = any> = Ref<T> | ComputedRef<T> | (() => T)

export type WatchCallback<V = any, OV = any> = (
value: V,
oldValue: OV,
onCleanup: CleanupRegistrator
onInvalidate: InvalidateCbRegistrator
) => any

type MapSources<T> = {
Expand All @@ -54,7 +54,7 @@ type MapOldSources<T, Immediate> = {
: never
}

export type CleanupRegistrator = (invalidate: () => void) => void
type InvalidateCbRegistrator = (cb: () => void) => void

export interface BaseWatchOptions {
flush?: 'pre' | 'post' | 'sync'
Expand Down Expand Up @@ -169,7 +169,7 @@ function doWatch(
source,
instance,
ErrorCodes.WATCH_CALLBACK,
[registerCleanup]
[onInvalidate]
)
}
}
Expand All @@ -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)
}
Expand All @@ -195,7 +195,7 @@ function doWatch(
callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
getter(),
undefined,
registerCleanup
onInvalidate
])
}
return NOOP
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export {
// types
WatchOptions,
WatchCallback,
CleanupRegistrator,
WatchSource,
StopHandle
} from './apiWatch'
Expand Down

0 comments on commit e42d6b0

Please sign in to comment.