type InvalidateCbRegistrator = (cb: () => void) => void
-export interface BaseWatchOptions {
+export interface WatchOptionsBase {
flush?: 'pre' | 'post' | 'sync'
onTrack?: ReactiveEffectOptions['onTrack']
onTrigger?: ReactiveEffectOptions['onTrigger']
}
-export interface WatchOptions<Immediate = boolean> extends BaseWatchOptions {
+export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
immediate?: Immediate
deep?: boolean
}
-export type StopHandle = () => void
+export type WatchStopHandle = () => void
const invoke = (fn: Function) => fn()
// Simple effect.
export function watchEffect(
effect: WatchEffect,
- options?: BaseWatchOptions
-): StopHandle {
+ options?: WatchOptionsBase
+): WatchStopHandle {
return doWatch(effect, null, options)
}
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
options?: WatchOptions<Immediate>
-): StopHandle
+): WatchStopHandle
// overload #2: array of multiple sources + cb
// Readonly constraint helps the callback to correctly infer value types based
sources: T,
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchOptions<Immediate>
-): StopHandle
+): WatchStopHandle
// implementation
export function watch<T = any>(
source: WatchSource<T> | WatchSource<T>[],
cb: WatchCallback<T>,
options?: WatchOptions
-): StopHandle {
+): WatchStopHandle {
if (__DEV__ && !isFunction(cb)) {
warn(
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
source: WatchSource | WatchSource[] | WatchEffect,
cb: WatchCallback | null,
{ immediate, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ
-): StopHandle {
+): WatchStopHandle {
if (__DEV__ && !cb) {
if (immediate !== undefined) {
warn(
source: string | Function,
cb: Function,
options?: WatchOptions
-): StopHandle {
+): WatchStopHandle {
const publicThis = this.proxy as any
const getter = isString(source)
? () => publicThis[source]