feat: clone observable data instead of warning

This commit is contained in:
Evan You 2018-10-04 16:13:02 -04:00
parent 03390f80a7
commit 3c49b30e17

View File

@ -9,7 +9,7 @@ import {
createFragment,
createPortal
} from './vdom'
import { isObservable } from '@vue/observer'
import { isObservable, unwrap } from '@vue/observer'
export const Fragment = Symbol()
export const Portal = Symbol()
@ -43,11 +43,10 @@ export const h = ((tag: ElementType, data?: any, children?: any): VNode => {
if (data === void 0) data = null
if (children === void 0) children = null
if (__DEV__ && isObservable(data)) {
console.warn(
`Do not used observed state as VNode data - always create fresh objects.`,
data
)
// if value is observable, create a clone of original
// so that we can mutate it later on.
if (isObservable(data)) {
data = Object.assign({}, unwrap(data))
}
let key = null