Skip to content

Commit

Permalink
fix(api-watch): watching nested ref array w/ deep doesn't work (#808)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz authored Sep 9, 2021
1 parent 6f893df commit b625420
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/apis/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ function createWatcher(
}

const applyCb = (n: any, o: any) => {
if (isMultiSource && n.every((v: any, i: number) => Object.is(v, o[i])))
if (
!deep &&
isMultiSource &&
n.every((v: any, i: number) => Object.is(v, o[i]))
)
return
// cleanup before running cb again
runCleanup()
Expand Down
10 changes: 10 additions & 0 deletions test/v3/runtime-core/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,14 @@ describe('api: watch', () => {
await nextTick()
expect(dummy).toEqual([1, 2])
})

// #805 #807
it('watching sources: [ref<[]>] w/ deep', async () => {
const foo = ref([1])
const cb = jest.fn()
watch([foo], cb, { deep: true })
foo.value.push(2)
await nextTick()
expect(cb).toBeCalledTimes(1)
})
})

0 comments on commit b625420

Please sign in to comment.