refactor: remove old watch signature support
This commit is contained in:
parent
52cc7e8231
commit
711d16cc65
@ -82,20 +82,14 @@ export function watchEffect(
|
|||||||
// initial value for watchers to trigger on undefined initial values
|
// initial value for watchers to trigger on undefined initial values
|
||||||
const INITIAL_WATCHER_VALUE = {}
|
const INITIAL_WATCHER_VALUE = {}
|
||||||
|
|
||||||
// overload #1: simple effect
|
// overload #1: single source + cb
|
||||||
export function watch(
|
|
||||||
effect: WatchEffect,
|
|
||||||
options?: BaseWatchOptions
|
|
||||||
): StopHandle
|
|
||||||
|
|
||||||
// overload #2: single source + cb
|
|
||||||
export function watch<T, Immediate extends Readonly<boolean> = false>(
|
export function watch<T, Immediate extends Readonly<boolean> = false>(
|
||||||
source: WatchSource<T>,
|
source: WatchSource<T>,
|
||||||
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
|
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
|
||||||
options?: WatchOptions<Immediate>
|
options?: WatchOptions<Immediate>
|
||||||
): StopHandle
|
): StopHandle
|
||||||
|
|
||||||
// overload #3: array of multiple sources + cb
|
// overload #2: array of multiple sources + cb
|
||||||
// Readonly constraint helps the callback to correctly infer value types based
|
// Readonly constraint helps the callback to correctly infer value types based
|
||||||
// on position in the source array. Otherwise the values will get a union type
|
// on position in the source array. Otherwise the values will get a union type
|
||||||
// of all possible value types.
|
// of all possible value types.
|
||||||
@ -110,24 +104,18 @@ export function watch<
|
|||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
export function watch<T = any>(
|
export function watch<T = any>(
|
||||||
effectOrSource: WatchSource<T> | WatchSource<T>[] | WatchEffect,
|
source: WatchSource<T> | WatchSource<T>[],
|
||||||
cbOrOptions?: WatchCallback<T> | WatchOptions,
|
cb: WatchCallback<T>,
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): StopHandle {
|
): StopHandle {
|
||||||
if (isFunction(cbOrOptions)) {
|
if (__DEV__ && !isFunction(cb)) {
|
||||||
// watch(source, cb)
|
warn(
|
||||||
return doWatch(effectOrSource, cbOrOptions, options)
|
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
||||||
} else {
|
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
|
||||||
// TODO remove this in the next release
|
`supports \`watch(source, cb, options?) signature.`
|
||||||
__DEV__ &&
|
)
|
||||||
warn(
|
|
||||||
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
|
||||||
`Use \`watchEffect(fn, options?)\` instead. \`watch\` will only ` +
|
|
||||||
`support \`watch(source, cb, options?) signature in the next release.`
|
|
||||||
)
|
|
||||||
// watch(effect)
|
|
||||||
return doWatch(effectOrSource, null, cbOrOptions)
|
|
||||||
}
|
}
|
||||||
|
return doWatch(source, cb, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
function doWatch(
|
function doWatch(
|
||||||
|
Loading…
Reference in New Issue
Block a user