From: Evan You Date: Tue, 30 Oct 2018 04:42:26 +0000 (-0400) Subject: chore: add warning when attempting to mutate non-observable hooks return value X-Git-Tag: v3.0.0-alpha.0~1059 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9e3e38fdb8aba75b3214c0434ccbb40ce0afb16;p=thirdparty%2Fvuejs%2Fcore.git chore: add warning when attempting to mutate non-observable hooks return value --- diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 43be11369c..8319a962dc 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -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