Skip to content

Commit

Permalink
fix(watch): fix deep watchers on refs containing primitives (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Apr 17, 2020
1 parent c0adb67 commit 99fd158
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ describe('api: watch', () => {
expect(dummy).toMatchObject([2, 1])
})

it('watching primitive with deep: true', async () => {
const count = ref(0)
let dummy
watch(
count,
(c, prevCount) => {
dummy = [c, prevCount]
},
{
deep: true
}
)
count.value++
await nextTick()
expect(dummy).toMatchObject([1, 0])
})

it('watching multiple sources', async () => {
const state = reactive({ count: 1 })
const count = ref(1)
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ export function instanceWatch(

function traverse(value: unknown, seen: Set<unknown> = new Set()) {
if (!isObject(value) || seen.has(value)) {
return value
}
if (seen.has(value)) {

This comment has been minimized.

Copy link
@DudaevAR

DudaevAR Apr 17, 2020

Strange conditions. It will never be completed due to line 288

return
}
seen.add(value)
Expand Down

0 comments on commit 99fd158

Please sign in to comment.