types: Use unique symbol type for _isRef property of ref object (#118)

This commit is contained in:
Rahul Kadyan 2019-10-06 08:02:50 +05:30 committed by Evan You
parent caa9297da6
commit f58e5e96f2
3 changed files with 4 additions and 2 deletions

View File

@ -78,6 +78,7 @@ describe('reactivity/ref', () => {
expect(isRef(computed(() => 1))).toBe(true) expect(isRef(computed(() => 1))).toBe(true)
expect(isRef(0)).toBe(false) expect(isRef(0)).toBe(false)
expect(isRef(1)).toBe(false)
// an object that looks like a ref isn't necessarily a ref // an object that looks like a ref isn't necessarily a ref
expect(isRef({ value: 0 })).toBe(false) expect(isRef({ value: 0 })).toBe(false)
}) })

View File

@ -131,7 +131,7 @@ export function track(
targetMap.set(target, (depsMap = new Map())) targetMap.set(target, (depsMap = new Map()))
} }
let dep = depsMap.get(key!) let dep = depsMap.get(key!)
if (!dep) { if (dep === void 0) {
depsMap.set(key!, (dep = new Set())) depsMap.set(key!, (dep = new Set()))
} }
if (!dep.has(effect)) { if (!dep.has(effect)) {

View File

@ -4,9 +4,10 @@ import { isObject } from '@vue/shared'
import { reactive } from './reactive' import { reactive } from './reactive'
export const refSymbol = Symbol() export const refSymbol = Symbol()
export type RefSymbol = typeof refSymbol
export interface Ref<T> { export interface Ref<T> {
_isRef: symbol _isRef: RefSymbol
value: UnwrapNestedRefs<T> value: UnwrapNestedRefs<T>
} }