From: Evan You Date: Mon, 9 Dec 2024 13:47:55 +0000 (+0800) Subject: fix(reactivity): toRefs should be allowed on plain objects X-Git-Tag: v3.6.0-alpha.1~16^2~186 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac43b118975b17d7ce7d9e6886f8806af11bee55;p=thirdparty%2Fvuejs%2Fcore.git fix(reactivity): toRefs should be allowed on plain objects --- diff --git a/packages/reactivity/__tests__/ref.spec.ts b/packages/reactivity/__tests__/ref.spec.ts index 7976a5373b..b6fd23ed39 100644 --- a/packages/reactivity/__tests__/ref.spec.ts +++ b/packages/reactivity/__tests__/ref.spec.ts @@ -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) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 6b8d541819..5bf9f019f4 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -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 = { * @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs} */ export function toRefs(object: T): ToRefs { - 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)