Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(reactive): align behavior with vue-next (#689)
  • Loading branch information
ygj6 committed Apr 29, 2021
1 parent badff82 commit 37fcbaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/reactivity/reactive.ts
@@ -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
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

0 comments on commit 37fcbaa

Please sign in to comment.