mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-29 18:47:39 +08:00
fix(watch): fix deep watch for structures containing raw refs
fix #12652
This commit is contained in:
parent
005e52d0b6
commit
1a2c3c2d77
@ -1,6 +1,7 @@
|
|||||||
import { _Set as Set, isObject, isArray } from '../util/index'
|
import { _Set as Set, isObject, isArray } from '../util/index'
|
||||||
import type { SimpleSet } from '../util/index'
|
import type { SimpleSet } from '../util/index'
|
||||||
import VNode from '../vdom/vnode'
|
import VNode from '../vdom/vnode'
|
||||||
|
import { isRef } from '../../v3'
|
||||||
|
|
||||||
const seenObjects = new Set()
|
const seenObjects = new Set()
|
||||||
|
|
||||||
@ -35,6 +36,8 @@ function _traverse(val: any, seen: SimpleSet) {
|
|||||||
if (isA) {
|
if (isA) {
|
||||||
i = val.length
|
i = val.length
|
||||||
while (i--) _traverse(val[i], seen)
|
while (i--) _traverse(val[i], seen)
|
||||||
|
} else if (isRef(val)) {
|
||||||
|
_traverse(val.value, seen)
|
||||||
} else {
|
} else {
|
||||||
keys = Object.keys(val)
|
keys = Object.keys(val)
|
||||||
i = keys.length
|
i = keys.length
|
||||||
|
@ -144,6 +144,20 @@ describe('api: watch', () => {
|
|||||||
expect(dummy).toBe(1)
|
expect(dummy).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('deep watch w/ raw refs', async () => {
|
||||||
|
const count = ref(0)
|
||||||
|
const src = reactive({
|
||||||
|
arr: [count]
|
||||||
|
})
|
||||||
|
let dummy
|
||||||
|
watch(src, ({ arr: [{ value }] }) => {
|
||||||
|
dummy = value
|
||||||
|
})
|
||||||
|
count.value++
|
||||||
|
await nextTick()
|
||||||
|
expect(dummy).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
it('watching multiple sources', async () => {
|
it('watching multiple sources', async () => {
|
||||||
const state = reactive({ count: 1 })
|
const state = reactive({ count: 1 })
|
||||||
const count = ref(1)
|
const count = ref(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user