refactor: tweak watch getter logic
This commit is contained in:
parent
fc5bf5cbe1
commit
caad39c353
@ -33,6 +33,8 @@ import { currentInstance } from './component'
|
|||||||
import { queueJob, queuePostFlushCb } from './scheduler'
|
import { queueJob, queuePostFlushCb } from './scheduler'
|
||||||
import { EMPTY_OBJ, isObject, isArray } from '@vue/shared'
|
import { EMPTY_OBJ, isObject, isArray } from '@vue/shared'
|
||||||
|
|
||||||
|
// record effects created during a component's setup() so that they can be
|
||||||
|
// stopped when the component unmounts
|
||||||
function recordEffect(effect: ReactiveEffect) {
|
function recordEffect(effect: ReactiveEffect) {
|
||||||
if (currentInstance) {
|
if (currentInstance) {
|
||||||
;(currentInstance.effects || (currentInstance.effects = [])).push(effect)
|
;(currentInstance.effects || (currentInstance.effects = [])).push(effect)
|
||||||
@ -71,11 +73,8 @@ export function watch<T>(
|
|||||||
? queueJob
|
? queueJob
|
||||||
: queuePostFlushCb
|
: queuePostFlushCb
|
||||||
|
|
||||||
const traverseIfDeep = (getter: Function) =>
|
const baseGetter = isValue(source) ? () => source.value : source
|
||||||
options.deep ? () => traverse(getter()) : getter
|
const getter = options.deep ? () => traverse(baseGetter()) : baseGetter
|
||||||
const getter = isValue(source)
|
|
||||||
? traverseIfDeep(() => source.value)
|
|
||||||
: traverseIfDeep(source)
|
|
||||||
|
|
||||||
let oldValue: any
|
let oldValue: any
|
||||||
const applyCb = cb
|
const applyCb = cb
|
||||||
|
Loading…
x
Reference in New Issue
Block a user