feat(reactivity): return array when calling toRefs on array (#1768)

close #1764
This commit is contained in:
Jordan Pittman
2020-08-18 12:11:13 -04:00
committed by GitHub
parent fdb2f418cf
commit 4172fdb90c
2 changed files with 24 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
import { track, trigger } from './effect'
import { TrackOpTypes, TriggerOpTypes } from './operations'
import { isObject, hasChanged } from '@vue/shared'
import { isArray, isObject, hasChanged } from '@vue/shared'
import { reactive, isProxy, toRaw, isReactive } from './reactive'
import { CollectionTypes } from './collectionHandlers'
@@ -121,7 +121,7 @@ export function toRefs<T extends object>(object: T): ToRefs<T> {
if (__DEV__ && !isProxy(object)) {
console.warn(`toRefs() expects a reactive object but received a plain one.`)
}
const ret: any = {}
const ret: any = isArray(object) ? new Array(object.length) : {}
for (const key in object) {
ret[key] = toRef(object, key)
}