From f80a4ff318d28481d53ff3823fa006e0a54d48e7 Mon Sep 17 00:00:00 2001 From: ygj6 Date: Tue, 8 Jun 2021 15:19:50 +0800 Subject: [PATCH] fix(watch): watched previos values can't be destructure on first fire --- src/apis/watch.ts | 1 + test/apis/watch.spec.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apis/watch.ts b/src/apis/watch.ts index 3f614141..6a2b27e6 100644 --- a/src/apis/watch.ts +++ b/src/apis/watch.ts @@ -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) => { diff --git a/test/apis/watch.spec.js b/test/apis/watch.spec.js index 33f5b626..eeb323e6 100644 --- a/test/apis/watch.spec.js +++ b/test/apis/watch.spec.js @@ -457,7 +457,7 @@ describe('api/watch', () => { template: `
{{obj1.a}} {{obj2.a}}
`, }).$mount() expect(spy).toBeCalledTimes(1) - expect(spy).toHaveBeenLastCalledWith([1, 2], undefined) + expect(spy).toHaveBeenLastCalledWith([1, 2], []) obj1.a = 2 obj2.a = 3 @@ -491,7 +491,7 @@ describe('api/watch', () => { template: `
{{a}} {{b}}
`, }).$mount() expect(spy).toBeCalledTimes(1) - expect(spy).toHaveBeenLastCalledWith([1, 1], undefined) + expect(spy).toHaveBeenLastCalledWith([1, 1], []) vm.a = 2 expect(spy).toBeCalledTimes(1) waitForUpdate(() => { @@ -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])