]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: warn when toRefs() receives non-reactive object (#430)
authorJunyan <yancoding@gmail.com>
Tue, 5 Nov 2019 15:44:28 +0000 (23:44 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 5 Nov 2019 15:44:28 +0000 (10:44 -0500)
packages/reactivity/src/ref.ts

index 472e951cb099f806c8425dd0fe019a3ae6a2e6fb..284bf6c1aa2820062e4077f5db8155b5856bd9eb 100644 (file)
@@ -1,7 +1,7 @@
 import { track, trigger } from './effect'
 import { OperationTypes } from './operations'
 import { isObject } from '@vue/shared'
-import { reactive } from './reactive'
+import { reactive, isReactive } from './reactive'
 import { ComputedRef } from './computed'
 import { CollectionTypes } from './collectionHandlers'
 
@@ -47,6 +47,9 @@ export function isRef(r: any): r is Ref {
 export function toRefs<T extends object>(
   object: T
 ): { [K in keyof T]: Ref<T[K]> } {
+  if (__DEV__ && !isReactive(object)) {
+    console.warn(`toRefs() expects a reactive object but received a plain one.`)
+  }
   const ret: any = {}
   for (const key in object) {
     ret[key] = toProxyRef(object, key)