Skip to content

Commit 5632e2f

Browse files
committed
refactor: baseWatch always return effect
1 parent 16ea5ff commit 5632e2f

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

packages/reactivity/src/baseWatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function baseWatch(
123123
onTrack,
124124
onTrigger,
125125
}: BaseWatchOptions = EMPTY_OBJ,
126-
): ReactiveEffect | undefined {
126+
): ReactiveEffect {
127127
const warnInvalidSource = (s: unknown) => {
128128
onWarn(
129129
`Invalid watch source: `,

packages/runtime-core/src/apiWatch.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,14 @@ function doWatch(
224224
handleErrorWithInstance(err, instance, type)
225225
extendOptions.scheduler = getScheduler(flush)(instance)
226226

227-
let effect = baseWatch(source, cb, extend({}, options, extendOptions))
228-
227+
const effect = baseWatch(source, cb, extend({}, options, extendOptions))
229228
const scope = getCurrentScope()
230-
const unwatch = !effect
231-
? NOOP
232-
: () => {
233-
effect!.stop()
234-
if (scope) {
235-
remove(scope.effects, effect)
236-
}
237-
}
229+
const unwatch = () => {
230+
effect!.stop()
231+
if (scope) {
232+
remove(scope.effects, effect)
233+
}
234+
}
238235

239236
if (__SSR__ && ssrCleanup) ssrCleanup.push(unwatch)
240237
return unwatch

packages/runtime-vapor/src/apiWatch.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
baseWatch,
88
getCurrentScope,
99
} from '@vue/reactivity'
10-
import { EMPTY_OBJ, NOOP, extend, isFunction, remove } from '@vue/shared'
10+
import { EMPTY_OBJ, extend, isFunction, remove } from '@vue/shared'
1111
import { currentInstance } from './component'
1212
import {
1313
type SchedulerFactory,
@@ -159,14 +159,6 @@ function doWatch(
159159
): WatchStopHandle {
160160
const { immediate, deep, flush, once } = options
161161

162-
// TODO remove in 3.5
163-
if (__DEV__ && deep !== void 0 && typeof deep === 'number') {
164-
warn(
165-
`watch() "deep" option with number value will be used as watch depth in future versions. ` +
166-
`Please use a boolean instead to avoid potential breakage.`,
167-
)
168-
}
169-
170162
if (__DEV__ && !cb) {
171163
if (immediate !== undefined) {
172164
warn(
@@ -213,17 +205,14 @@ function doWatch(
213205
handleErrorWithInstance(err, instance, type)
214206
extendOptions.scheduler = getScheduler(flush)(instance)
215207

216-
let effect = baseWatch(source, cb, extend({}, options, extendOptions))
217-
208+
const effect = baseWatch(source, cb, extend({}, options, extendOptions))
218209
const scope = getCurrentScope()
219-
const unwatch = !effect
220-
? NOOP
221-
: () => {
222-
effect!.stop()
223-
if (scope) {
224-
remove(scope.effects, effect)
225-
}
226-
}
210+
const unwatch = () => {
211+
effect!.stop()
212+
if (scope) {
213+
remove(scope.effects, effect)
214+
}
215+
}
227216

228217
if (__SSR__ && ssrCleanup) ssrCleanup.push(unwatch)
229218
return unwatch

0 commit comments

Comments
 (0)