Browse Source

feat: warn when toRefs() receives non-reactive object (#430)

Junyan 6 years ago
parent
commit
a02820d7e0
1 changed files with 4 additions and 1 deletions
  1. 4 1
      packages/reactivity/src/ref.ts

+ 4 - 1
packages/reactivity/src/ref.ts

@@ -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)