]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(watch): ignore lazy option in simple watch (#546)
authorYang Mingshan <y.mingshan3@gmail.com>
Wed, 18 Dec 2019 16:46:59 +0000 (00:46 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 18 Dec 2019 16:46:59 +0000 (11:46 -0500)
* fix(watch): ignore lazy option in simple watch

* test: ignore lazy option in simple watch

packages/runtime-core/__tests__/apiWatch.spec.ts
packages/runtime-core/src/apiWatch.ts

index 65710c65c55cd9b73af5bff25cf18ea56f19b740..ed2276f729a3404bc37c997ca7bd2b1580541f79 100644 (file)
@@ -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
index efd3dfd40a4f9ee4272be88257626060e453c405..22828316edfc91c22474429fd930306c3343f139 100644 (file)
@@ -197,7 +197,7 @@ function doWatch(
     scheduler: applyCb ? () => scheduler(applyCb) : scheduler
   })
 
-  if (!lazy) {
+  if (!lazy || !cb) {
     if (applyCb) {
       scheduler(applyCb)
     } else {