Skip to content

Commit b625420

Browse files
authored
fix(api-watch): watching nested ref array w/ deep doesn't work (#808)
Co-authored-by: webfansplz <>
1 parent 6f893df commit b625420

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/apis/watch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ function createWatcher(
341341
}
342342

343343
const applyCb = (n: any, o: any) => {
344-
if (isMultiSource && n.every((v: any, i: number) => Object.is(v, o[i])))
344+
if (
345+
!deep &&
346+
isMultiSource &&
347+
n.every((v: any, i: number) => Object.is(v, o[i]))
348+
)
345349
return
346350
// cleanup before running cb again
347351
runCleanup()

test/v3/runtime-core/apiWatch.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,4 +572,14 @@ describe('api: watch', () => {
572572
await nextTick()
573573
expect(dummy).toEqual([1, 2])
574574
})
575+
576+
// #805 #807
577+
it('watching sources: [ref<[]>] w/ deep', async () => {
578+
const foo = ref([1])
579+
const cb = jest.fn()
580+
watch([foo], cb, { deep: true })
581+
foo.value.push(2)
582+
await nextTick()
583+
expect(cb).toBeCalledTimes(1)
584+
})
575585
})

0 commit comments

Comments
 (0)