refactor(reactivity): change _isRef to use refSymbol as key (#124)

This commit is contained in:
Carlos Rodrigues 2019-10-06 16:46:09 +01:00 committed by Evan You
parent 12b7557e8f
commit 8d70093802
2 changed files with 6 additions and 7 deletions

View File

@ -45,7 +45,7 @@ export function computed<T>(
}
})
return {
_isRef: refSymbol,
[refSymbol]: true,
// expose effect so computed can be stopped
effect: runner,
get value() {

View File

@ -3,11 +3,10 @@ import { OperationTypes } from './operations'
import { isObject } from '@vue/shared'
import { reactive } from './reactive'
export const refSymbol = Symbol()
export type RefSymbol = typeof refSymbol
export const refSymbol = Symbol(__DEV__ ? 'refSymbol' : undefined)
export interface Ref<T> {
_isRef: RefSymbol
[refSymbol]: true
value: UnwrapNestedRefs<T>
}
@ -18,7 +17,7 @@ const convert = (val: any): any => (isObject(val) ? reactive(val) : val)
export function ref<T>(raw: T): Ref<T> {
raw = convert(raw)
const v = {
_isRef: refSymbol,
[refSymbol]: true,
get value() {
track(v, OperationTypes.GET, '')
return raw
@ -32,7 +31,7 @@ export function ref<T>(raw: T): Ref<T> {
}
export function isRef(v: any): v is Ref<any> {
return v ? v._isRef === refSymbol : false
return v ? v[refSymbol] === true : false
}
export function toRefs<T extends object>(
@ -50,7 +49,7 @@ function toProxyRef<T extends object, K extends keyof T>(
key: K
): Ref<T[K]> {
const v = {
_isRef: refSymbol,
[refSymbol]: true,
get value() {
return object[key]
},