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,
|
onTrack,
|
||||||
onTrigger,
|
onTrigger,
|
||||||
}: BaseWatchOptions = EMPTY_OBJ,
|
}: BaseWatchOptions = EMPTY_OBJ,
|
||||||
): ReactiveEffect | undefined {
|
): ReactiveEffect {
|
||||||
const warnInvalidSource = (s: unknown) => {
|
const warnInvalidSource = (s: unknown) => {
|
||||||
onWarn(
|
onWarn(
|
||||||
`Invalid watch source: `,
|
`Invalid watch source: `,
|
||||||
|
|
|
@ -224,12 +224,9 @@ function doWatch(
|
||||||
handleErrorWithInstance(err, instance, type)
|
handleErrorWithInstance(err, instance, type)
|
||||||
extendOptions.scheduler = getScheduler(flush)(instance)
|
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 scope = getCurrentScope()
|
||||||
const unwatch = !effect
|
const unwatch = () => {
|
||||||
? NOOP
|
|
||||||
: () => {
|
|
||||||
effect!.stop()
|
effect!.stop()
|
||||||
if (scope) {
|
if (scope) {
|
||||||
remove(scope.effects, effect)
|
remove(scope.effects, effect)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
baseWatch,
|
baseWatch,
|
||||||
getCurrentScope,
|
getCurrentScope,
|
||||||
} from '@vue/reactivity'
|
} 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 { currentInstance } from './component'
|
||||||
import {
|
import {
|
||||||
type SchedulerFactory,
|
type SchedulerFactory,
|
||||||
|
@ -159,14 +159,6 @@ function doWatch(
|
||||||
): WatchStopHandle {
|
): WatchStopHandle {
|
||||||
const { immediate, deep, flush, once } = options
|
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 (__DEV__ && !cb) {
|
||||||
if (immediate !== undefined) {
|
if (immediate !== undefined) {
|
||||||
warn(
|
warn(
|
||||||
|
@ -213,12 +205,9 @@ function doWatch(
|
||||||
handleErrorWithInstance(err, instance, type)
|
handleErrorWithInstance(err, instance, type)
|
||||||
extendOptions.scheduler = getScheduler(flush)(instance)
|
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 scope = getCurrentScope()
|
||||||
const unwatch = !effect
|
const unwatch = () => {
|
||||||
? NOOP
|
|
||||||
: () => {
|
|
||||||
effect!.stop()
|
effect!.stop()
|
||||||
if (scope) {
|
if (scope) {
|
||||||
remove(scope.effects, effect)
|
remove(scope.effects, effect)
|
||||||
|
|
Loading…
Reference in New Issue