chore: add warning when attempting to mutate non-observable hooks return value

This commit is contained in:
Evan You 2018-10-30 00:42:26 -04:00
parent a17c377be0
commit f9e3e38fdb

View 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