Skip to content

Commit

Permalink
fix(watch): watched previos values can't be destructure on first fire
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jun 8, 2021
1 parent d30a45a commit f80a4ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/apis/watch.ts
Expand Up @@ -329,6 +329,7 @@ function createWatcher(
// The subsequent callbacks will redirect to `callback`.
let shiftCallback = (n: any, o: any) => {
shiftCallback = originalCallback
o = isArray(n) ? [] : undefined
applyCb(n, o)
}
callback = (n: any, o: any) => {
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

0 comments on commit f80a4ff

Please sign in to comment.