Skip to content

Commit ac43b11

Browse files
committed
fix(reactivity): toRefs should be allowed on plain objects
1 parent b7aec13 commit ac43b11

File tree

2 files changed

+0
-15
lines changed

2 files changed

+0
-15
lines changed

packages/reactivity/__tests__/ref.spec.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,6 @@ describe('reactivity/ref', () => {
386386
expect(dummyY).toBe(5)
387387
})
388388

389-
test('toRefs should warn on plain object', () => {
390-
toRefs({})
391-
expect(`toRefs() expects a reactive object`).toHaveBeenWarned()
392-
})
393-
394-
test('toRefs should warn on plain array', () => {
395-
toRefs([])
396-
expect(`toRefs() expects a reactive object`).toHaveBeenWarned()
397-
})
398-
399389
test('toRefs reactive array', () => {
400390
const arr = reactive(['a', 'b', 'c'])
401391
const refs = toRefs(arr)

packages/reactivity/src/ref.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Dep, getDepFromReactive } from './dep'
99
import {
1010
type Builtin,
1111
type ShallowReactiveMarker,
12-
isProxy,
1312
isReactive,
1413
isReadonly,
1514
isShallow,
@@ -18,7 +17,6 @@ import {
1817
} from './reactive'
1918
import type { ComputedRef, WritableComputedRef } from './computed'
2019
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
21-
import { warn } from './warning'
2220

2321
declare const RefSymbol: unique symbol
2422
export declare const RawSymbol: unique symbol
@@ -337,9 +335,6 @@ export type ToRefs<T = any> = {
337335
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
338336
*/
339337
export function toRefs<T extends object>(object: T): ToRefs<T> {
340-
if (__DEV__ && !isProxy(object)) {
341-
warn(`toRefs() expects a reactive object but received a plain one.`)
342-
}
343338
const ret: any = isArray(object) ? new Array(object.length) : {}
344339
for (const key in object) {
345340
ret[key] = propertyToRef(object, key)

0 commit comments

Comments
 (0)