Skip to content

Commit 91a7db9

Browse files
committed
fix(watch): watched previous values can't be destructure on first fire
1 parent d30a45a commit 91a7db9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/apis/watch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ function createWatcher(
329329
// The subsequent callbacks will redirect to `callback`.
330330
let shiftCallback = (n: any, o: any) => {
331331
shiftCallback = originalCallback
332+
o = isArray(n) ? [] : undefined
332333
applyCb(n, o)
333334
}
334335
callback = (n: any, o: any) => {

test/apis/watch.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ describe('api/watch', () => {
457457
template: `<div>{{obj1.a}} {{obj2.a}}</div>`,
458458
}).$mount()
459459
expect(spy).toBeCalledTimes(1)
460-
expect(spy).toHaveBeenLastCalledWith([1, 2], undefined)
460+
expect(spy).toHaveBeenLastCalledWith([1, 2], [])
461461
obj1.a = 2
462462
obj2.a = 3
463463

@@ -491,7 +491,7 @@ describe('api/watch', () => {
491491
template: `<div>{{a}} {{b}}</div>`,
492492
}).$mount()
493493
expect(spy).toBeCalledTimes(1)
494-
expect(spy).toHaveBeenLastCalledWith([1, 1], undefined)
494+
expect(spy).toHaveBeenLastCalledWith([1, 1], [])
495495
vm.a = 2
496496
expect(spy).toBeCalledTimes(1)
497497
waitForUpdate(() => {
@@ -553,7 +553,7 @@ describe('api/watch', () => {
553553
},
554554
})
555555
expect(spy).toBeCalledTimes(1)
556-
expect(spy).toHaveBeenLastCalledWith([1, 1], undefined)
556+
expect(spy).toHaveBeenLastCalledWith([1, 1], [])
557557
vm.a = 2
558558
expect(spy).toBeCalledTimes(2)
559559
expect(spy).toHaveBeenLastCalledWith([2, 1], [1, 1])

0 commit comments

Comments
 (0)