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(watch): watched previous values can't be destructure on first fire. #727

Merged
merged 2 commits into from Jun 17, 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
3 changes: 2 additions & 1 deletion src/apis/watch.ts
Expand Up @@ -329,7 +329,8 @@ function createWatcher(
// The subsequent callbacks will redirect to `callback`.
let shiftCallback = (n: any, o: any) => {
shiftCallback = originalCallback
applyCb(n, o)
// o is undefined on the first call
applyCb(n, isArray(n) ? [] : o)
}
callback = (n: any, o: any) => {
shiftCallback(n, o)
Expand Down
6 changes: 3 additions & 3 deletions test/apis/watch.spec.js
Expand Up @@ -457,7 +457,7 @@ describe('api/watch', () => {
template: `<div>{{obj1.a}} {{obj2.a}}</div>`,
}).$mount()
expect(spy).toBeCalledTimes(1)
expect(spy).toHaveBeenLastCalledWith([1, 2], undefined)
expect(spy).toHaveBeenLastCalledWith([1, 2], [])
obj1.a = 2
obj2.a = 3

Expand Down Expand Up @@ -491,7 +491,7 @@ describe('api/watch', () => {
template: `<div>{{a}} {{b}}</div>`,
}).$mount()
expect(spy).toBeCalledTimes(1)
expect(spy).toHaveBeenLastCalledWith([1, 1], undefined)
expect(spy).toHaveBeenLastCalledWith([1, 1], [])
vm.a = 2
expect(spy).toBeCalledTimes(1)
waitForUpdate(() => {
Expand Down Expand Up @@ -553,7 +553,7 @@ describe('api/watch', () => {
},
})
expect(spy).toBeCalledTimes(1)
expect(spy).toHaveBeenLastCalledWith([1, 1], undefined)
expect(spy).toHaveBeenLastCalledWith([1, 1], [])
vm.a = 2
expect(spy).toBeCalledTimes(2)
expect(spy).toHaveBeenLastCalledWith([2, 1], [1, 1])
Expand Down