]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: add warning when attempting to mutate non-observable hooks return value
authorEvan You <yyx990803@gmail.com>
Tue, 30 Oct 2018 04:42:26 +0000 (00:42 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 30 Oct 2018 04:42:26 +0000 (00:42 -0400)
packages/runtime-core/src/componentProxy.ts

index 43be11369c0801cecf215bcdfd5206e2a1641feb..8319a962dc1dbef9c7c3aac4f6e4c9ae4e5db90d 100644 (file)
@@ -2,6 +2,7 @@ import { ComponentInstance } from './component'
 import { isFunction, isReservedKey } from '@vue/shared'
 import { warn } from './warning'
 import { isRendering } from './componentUtils'
+import { isObservable } from '@vue/observer'
 
 const bindCache = new WeakMap()
 
@@ -75,6 +76,12 @@ const renderProxyHandlers = {
       target.$data[key] = value
       return true
     } else if ((i = target._hookProps) !== null && i.hasOwnProperty(key)) {
+      if (__DEV__ && !isObservable(i)) {
+        warn(
+          `attempting to mutate a property returned from hooks(), but the ` +
+            `value is not observable.`
+        )
+      }
       // this enables returning observable objects from hooks()
       i[key] = value
       return true