]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: clone observable data instead of warning
authorEvan You <yyx990803@gmail.com>
Thu, 4 Oct 2018 20:13:02 +0000 (16:13 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 4 Oct 2018 20:13:02 +0000 (16:13 -0400)
packages/core/src/h.ts

index 993a418a5d3dde014055ebf85a49baf30e7ad756..f423ddebf5f432cdb92f5aa2352674d31bf786e4 100644 (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