]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): toRefs should be allowed on plain objects
authorEvan You <evan@vuejs.org>
Mon, 9 Dec 2024 13:47:55 +0000 (21:47 +0800)
committerEvan You <evan@vuejs.org>
Mon, 9 Dec 2024 13:47:55 +0000 (21:47 +0800)
packages/reactivity/__tests__/ref.spec.ts
packages/reactivity/src/ref.ts

index 7976a5373baf6edd4ad7f0f83618b203eee47a82..b6fd23ed39bf601ef2a4ade4dbda5ee90dab8e6e 100644 (file)
@@ -386,16 +386,6 @@ describe('reactivity/ref', () => {
     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', () => {
     const arr = reactive(['a', 'b', 'c'])
     const refs = toRefs(arr)
index 6b8d541819d3701f0e4d0ca502346d1e40ae3248..5bf9f019f448e12a87ccfbda44809c8ac1b12574 100644 (file)
@@ -9,7 +9,6 @@ import { Dep, getDepFromReactive } from './dep'
 import {
   type Builtin,
   type ShallowReactiveMarker,
-  isProxy,
   isReactive,
   isReadonly,
   isShallow,
@@ -18,7 +17,6 @@ import {
 } from './reactive'
 import type { ComputedRef, WritableComputedRef } from './computed'
 import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
-import { warn } from './warning'
 
 declare const RefSymbol: 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}
  */
 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) : {}
   for (const key in object) {
     ret[key] = propertyToRef(object, key)