mirror of https://github.com/vuejs/core.git
refactor: `baseWatch` always return effect
This commit is contained in:
parent
16ea5ff2d6
commit
5632e2fe68
|
@ -123,7 +123,7 @@ export function baseWatch(
|
|||
onTrack,
|
||||
onTrigger,
|
||||
}: BaseWatchOptions = EMPTY_OBJ,
|
||||
): ReactiveEffect | undefined {
|
||||
): ReactiveEffect {
|
||||
const warnInvalidSource = (s: unknown) => {
|
||||
onWarn(
|
||||
`Invalid watch source: `,
|
||||
|
|
|
@ -224,17 +224,14 @@ function doWatch(
|
|||
handleErrorWithInstance(err, instance, type)
|
||||
extendOptions.scheduler = getScheduler(flush)(instance)
|
||||
|
||||
let effect = baseWatch(source, cb, extend({}, options, extendOptions))
|
||||
|
||||
const effect = baseWatch(source, cb, extend({}, options, extendOptions))
|
||||
const scope = getCurrentScope()
|
||||
const unwatch = !effect
|
||||
? NOOP
|
||||
: () => {
|
||||
effect!.stop()
|
||||
if (scope) {
|
||||
remove(scope.effects, effect)
|
||||
}
|
||||
}
|
||||
const unwatch = () => {
|
||||
effect!.stop()
|
||||
if (scope) {
|
||||
remove(scope.effects, effect)
|
||||
}
|
||||
}
|
||||
|
||||
if (__SSR__ && ssrCleanup) ssrCleanup.push(unwatch)
|
||||
return unwatch
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
baseWatch,
|
||||
getCurrentScope,
|
||||
} from '@vue/reactivity'
|
||||
import { EMPTY_OBJ, NOOP, extend, isFunction, remove } from '@vue/shared'
|
||||
import { EMPTY_OBJ, extend, isFunction, remove } from '@vue/shared'
|
||||
import { currentInstance } from './component'
|
||||
import {
|
||||
type SchedulerFactory,
|
||||
|
@ -159,14 +159,6 @@ function doWatch(
|
|||
): WatchStopHandle {
|
||||
const { immediate, deep, flush, once } = options
|
||||
|
||||
// TODO remove in 3.5
|
||||
if (__DEV__ && deep !== void 0 && typeof deep === 'number') {
|
||||
warn(
|
||||
`watch() "deep" option with number value will be used as watch depth in future versions. ` +
|
||||
`Please use a boolean instead to avoid potential breakage.`,
|
||||
)
|
||||
}
|
||||
|
||||
if (__DEV__ && !cb) {
|
||||
if (immediate !== undefined) {
|
||||
warn(
|
||||
|
@ -213,17 +205,14 @@ function doWatch(
|
|||
handleErrorWithInstance(err, instance, type)
|
||||
extendOptions.scheduler = getScheduler(flush)(instance)
|
||||
|
||||
let effect = baseWatch(source, cb, extend({}, options, extendOptions))
|
||||
|
||||
const effect = baseWatch(source, cb, extend({}, options, extendOptions))
|
||||
const scope = getCurrentScope()
|
||||
const unwatch = !effect
|
||||
? NOOP
|
||||
: () => {
|
||||
effect!.stop()
|
||||
if (scope) {
|
||||
remove(scope.effects, effect)
|
||||
}
|
||||
}
|
||||
const unwatch = () => {
|
||||
effect!.stop()
|
||||
if (scope) {
|
||||
remove(scope.effects, effect)
|
||||
}
|
||||
}
|
||||
|
||||
if (__SSR__ && ssrCleanup) ssrCleanup.push(unwatch)
|
||||
return unwatch
|
||||
|
|
Loading…
Reference in New Issue