Skip to content

Commit 711d16c

Browse files
committed
refactor: remove old watch signature support
1 parent 52cc7e8 commit 711d16c

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

packages/runtime-core/src/apiWatch.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,14 @@ export function watchEffect(
8282
// initial value for watchers to trigger on undefined initial values
8383
const INITIAL_WATCHER_VALUE = {}
8484

85-
// overload #1: simple effect
86-
export function watch(
87-
effect: WatchEffect,
88-
options?: BaseWatchOptions
89-
): StopHandle
90-
91-
// overload #2: single source + cb
85+
// overload #1: single source + cb
9286
export function watch<T, Immediate extends Readonly<boolean> = false>(
9387
source: WatchSource<T>,
9488
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
9589
options?: WatchOptions<Immediate>
9690
): StopHandle
9791

98-
// overload #3: array of multiple sources + cb
92+
// overload #2: array of multiple sources + cb
9993
// Readonly constraint helps the callback to correctly infer value types based
10094
// on position in the source array. Otherwise the values will get a union type
10195
// of all possible value types.
@@ -110,24 +104,18 @@ export function watch<
110104

111105
// implementation
112106
export function watch<T = any>(
113-
effectOrSource: WatchSource<T> | WatchSource<T>[] | WatchEffect,
114-
cbOrOptions?: WatchCallback<T> | WatchOptions,
107+
source: WatchSource<T> | WatchSource<T>[],
108+
cb: WatchCallback<T>,
115109
options?: WatchOptions
116110
): StopHandle {
117-
if (isFunction(cbOrOptions)) {
118-
// watch(source, cb)
119-
return doWatch(effectOrSource, cbOrOptions, options)
120-
} else {
121-
// TODO remove this in the next release
122-
__DEV__ &&
123-
warn(
124-
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
125-
`Use \`watchEffect(fn, options?)\` instead. \`watch\` will only ` +
126-
`support \`watch(source, cb, options?) signature in the next release.`
127-
)
128-
// watch(effect)
129-
return doWatch(effectOrSource, null, cbOrOptions)
111+
if (__DEV__ && !isFunction(cb)) {
112+
warn(
113+
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
114+
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
115+
`supports \`watch(source, cb, options?) signature.`
116+
)
130117
}
118+
return doWatch(source, cb, options)
131119
}
132120

133121
function doWatch(

0 commit comments

Comments
 (0)