mirror of https://github.com/vuejs/core.git
fix(reactivity): toRefs should be allowed on plain objects
This commit is contained in:
parent
b7aec139cb
commit
ac43b11897
|
@ -386,16 +386,6 @@ describe('reactivity/ref', () => {
|
||||||
expect(dummyY).toBe(5)
|
expect(dummyY).toBe(5)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('toRefs should warn on plain object', () => {
|
|
||||||
toRefs({})
|
|
||||||
expect(`toRefs() expects a reactive object`).toHaveBeenWarned()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('toRefs should warn on plain array', () => {
|
|
||||||
toRefs([])
|
|
||||||
expect(`toRefs() expects a reactive object`).toHaveBeenWarned()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('toRefs reactive array', () => {
|
test('toRefs reactive array', () => {
|
||||||
const arr = reactive(['a', 'b', 'c'])
|
const arr = reactive(['a', 'b', 'c'])
|
||||||
const refs = toRefs(arr)
|
const refs = toRefs(arr)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { Dep, getDepFromReactive } from './dep'
|
||||||
import {
|
import {
|
||||||
type Builtin,
|
type Builtin,
|
||||||
type ShallowReactiveMarker,
|
type ShallowReactiveMarker,
|
||||||
isProxy,
|
|
||||||
isReactive,
|
isReactive,
|
||||||
isReadonly,
|
isReadonly,
|
||||||
isShallow,
|
isShallow,
|
||||||
|
@ -18,7 +17,6 @@ import {
|
||||||
} from './reactive'
|
} from './reactive'
|
||||||
import type { ComputedRef, WritableComputedRef } from './computed'
|
import type { ComputedRef, WritableComputedRef } from './computed'
|
||||||
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
|
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
|
||||||
import { warn } from './warning'
|
|
||||||
|
|
||||||
declare const RefSymbol: unique symbol
|
declare const RefSymbol: unique symbol
|
||||||
export declare const RawSymbol: unique symbol
|
export declare const RawSymbol: unique symbol
|
||||||
|
@ -337,9 +335,6 @@ export type ToRefs<T = any> = {
|
||||||
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
||||||
*/
|
*/
|
||||||
export function toRefs<T extends object>(object: T): ToRefs<T> {
|
export function toRefs<T extends object>(object: T): ToRefs<T> {
|
||||||
if (__DEV__ && !isProxy(object)) {
|
|
||||||
warn(`toRefs() expects a reactive object but received a plain one.`)
|
|
||||||
}
|
|
||||||
const ret: any = isArray(object) ? new Array(object.length) : {}
|
const ret: any = isArray(object) ? new Array(object.length) : {}
|
||||||
for (const key in object) {
|
for (const key in object) {
|
||||||
ret[key] = propertyToRef(object, key)
|
ret[key] = propertyToRef(object, key)
|
||||||
|
|
Loading…
Reference in New Issue