refactor: more readable type names for watch cleanup function
This commit is contained in:
parent
3007d5b4ca
commit
ce49fdf999
@ -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<T = any> = Ref<T> | ComputedRef<T> | (() => T)
|
||||
|
||||
export type WatchCallback<V = any, OV = any> = (
|
||||
value: V,
|
||||
oldValue: OV,
|
||||
onInvalidate: InvalidateCbRegistrator
|
||||
onCleanup: OnCleanup
|
||||
) => any
|
||||
|
||||
type MapSources<T, Immediate> = {
|
||||
@ -62,7 +62,7 @@ type MapSources<T, Immediate> = {
|
||||
: 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user