Skip to content

fix(reactive): align behavior with vue-next #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/reactivity/reactive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { AnyObject } from '../types/basic'
import { getRegisteredVueOrDefault } from '../runtimeContext'
import { isPlainObject, def, warn, isArray, hasOwn, noopFn } from '../utils'
import {
isPlainObject,
def,
warn,
isArray,
hasOwn,
noopFn,
isObject,
} from '../utils'
import { isComponentInstance, defineComponentInstance } from '../utils/helper'
import { RefKey } from '../utils/symbols'
import { isRef, UnwrapRef } from './ref'
Expand Down Expand Up @@ -190,10 +198,11 @@ export function shallowReactive(obj: any): any {
* Make obj reactivity
*/
export function reactive<T extends object>(obj: T): UnwrapRef<T> {
if (__DEV__ && !obj) {
warn('"reactive()" is called without provide an "object".')
// @ts-ignore
return
if (!isObject(obj)) {
if (__DEV__) {
warn('"reactive()" is called without provide an "object".')
}
return obj as any
}

if (
Expand Down
3 changes: 2 additions & 1 deletion test/v3/reactivity/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe('reactivity/reactive', () => {
test('non-observable values', () => {
const assertValue = (value: any) => {
expect(isReactive(reactive(value))).toBe(false)
expect(reactive(value)).toBe(value)
// expect(warnSpy).toHaveBeenLastCalledWith(`value cannot be made reactive: ${String(value)}`);
}

Expand All @@ -167,7 +168,7 @@ describe('reactivity/reactive', () => {
const d = new Date()
expect(reactive(d)).toBe(d)

expect(warn).toBeCalledTimes(3)
expect(warn).toBeCalledTimes(12)
expect(
warn.mock.calls.map((call) => {
expect(call[0]).toBe(
Expand Down