Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(watch): fix deep watch for structures containing raw refs
fix #12652
  • Loading branch information
yyx990803 committed Jul 13, 2022
1 parent 005e52d commit 1a2c3c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/observer/traverse.ts
@@ -1,6 +1,7 @@
import { _Set as Set, isObject, isArray } from '../util/index'
import type { SimpleSet } from '../util/index'
import VNode from '../vdom/vnode'
import { isRef } from '../../v3'

const seenObjects = new Set()

Expand Down Expand Up @@ -35,6 +36,8 @@ function _traverse(val: any, seen: SimpleSet) {
if (isA) {
i = val.length
while (i--) _traverse(val[i], seen)
} else if (isRef(val)) {
_traverse(val.value, seen)
} else {
keys = Object.keys(val)
i = keys.length
Expand Down
14 changes: 14 additions & 0 deletions test/unit/features/v3/apiWatch.spec.ts
Expand Up @@ -144,6 +144,20 @@ describe('api: watch', () => {
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 () => {
const state = reactive({ count: 1 })
const count = ref(1)
Expand Down

0 comments on commit 1a2c3c2

Please sign in to comment.