]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): make watchEffect ignore deep option (#765)
authordjy0 <krivergo3@gmail.com>
Mon, 24 Feb 2020 17:03:02 +0000 (01:03 +0800)
committerGitHub <noreply@github.com>
Mon, 24 Feb 2020 17:03:02 +0000 (18:03 +0100)
packages/runtime-core/__tests__/apiWatch.spec.ts
packages/runtime-core/src/apiWatch.ts

index 796b2cbff50d4d4d516c9608777b85bd0fac426a..36db04b1996e864e9f3e12ec0d535fc6d0eeff6f 100644 (file)
@@ -410,6 +410,24 @@ describe('api: watch', () => {
     expect(dummy).toBe(1)
   })
 
+  it('warn and not respect deep option when using effect', async () => {
+    const arr = ref([1, [2]])
+    let spy = jest.fn()
+    watchEffect(
+      () => {
+        spy()
+        return arr
+      },
+      // @ts-ignore
+      { deep: true }
+    )
+    expect(spy).toHaveBeenCalledTimes(1)
+    ;(arr.value[1] as Array<number>)[0] = 3
+    await nextTick()
+    expect(spy).toHaveBeenCalledTimes(1)
+    expect(`"deep" option is only respected`).toHaveBeenWarned()
+  })
+
   it('onTrack', async () => {
     const events: DebuggerEvent[] = []
     let dummy
index 1a2ecb5ec2fbb3379abcbeef252508066ff3689d..71cb485a533c0ee55c0669a38900c99bf455c860 100644 (file)
@@ -139,13 +139,13 @@ function doWatch(
     if (immediate !== undefined) {
       warn(
         `watch() "immediate" option is only respected when using the ` +
-          `watch(source, callback) signature.`
+          `watch(source, callback, options?) signature.`
       )
     }
     if (deep !== undefined) {
       warn(
         `watch() "deep" option is only respected when using the ` +
-          `watch(source, callback) signature.`
+          `watch(source, callback, options?) signature.`
       )
     }
   }
@@ -186,7 +186,7 @@ function doWatch(
     }
   }
 
-  if (deep) {
+  if (cb && deep) {
     const baseGetter = getter
     getter = () => traverse(baseGetter())
   }