From 3c49b30e1764053f4e7f880f00b5cff14265b833 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Oct 2018 16:13:02 -0400 Subject: [PATCH] feat: clone observable data instead of warning --- packages/core/src/h.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/core/src/h.ts b/packages/core/src/h.ts index 993a418a..f423ddeb 100644 --- a/packages/core/src/h.ts +++ b/packages/core/src/h.ts @@ -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