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> = {
: never
}
-export type CleanupRegistrator = (invalidate: () => void) => void
+type InvalidateCbRegistrator = (cb: () => void) => void
export interface BaseWatchOptions {
flush?: 'pre' | 'post' | 'sync'
source,
instance,
ErrorCodes.WATCH_CALLBACK,
- [registerCleanup]
+ [onInvalidate]
)
}
}
}
let cleanup: Function
- const registerCleanup: CleanupRegistrator = (fn: () => void) => {
+ const onInvalidate: InvalidateCbRegistrator = (fn: () => void) => {
cleanup = runner.options.onStop = () => {
callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP)
}
callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
getter(),
undefined,
- registerCleanup
+ onInvalidate
])
}
return NOOP
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
}