From c2c9c2b57e5d2e87da99bedb06b9e2d3e48b492e Mon Sep 17 00:00:00 2001 From: Yang Mingshan Date: Thu, 19 Dec 2019 00:46:59 +0800 Subject: [PATCH] fix(watch): ignore lazy option in simple watch (#546) * fix(watch): ignore lazy option in simple watch * test: ignore lazy option in simple watch --- .../runtime-core/__tests__/apiWatch.spec.ts | 19 +++++++++++++++++++ packages/runtime-core/src/apiWatch.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index 65710c65c5..ed2276f729 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -344,6 +344,25 @@ describe('api: watch', () => { expect(cb).toHaveBeenCalled() }) + it('ignore lazy', async () => { + const count = ref(0) + let dummy + watch( + () => { + dummy = count.value + }, + { lazy: true } + ) + expect(dummy).toBeUndefined() + + await nextTick() + expect(dummy).toBe(0) + + count.value++ + await nextTick() + expect(dummy).toBe(1) + }) + it('onTrack', async () => { const events: DebuggerEvent[] = [] let dummy diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index efd3dfd40a..22828316ed 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -197,7 +197,7 @@ function doWatch( scheduler: applyCb ? () => scheduler(applyCb) : scheduler }) - if (!lazy) { + if (!lazy || !cb) { if (applyCb) { scheduler(applyCb) } else { -- 2.47.3