Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-watch): watching nested ref array w/ deep doesn't work #808

Merged
merged 1 commit into from Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/apis/watch.ts
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
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)
})
})