refactor(reactivity): change _isRef to use refSymbol as key (#124)
This commit is contained in:
parent
12b7557e8f
commit
8d70093802
@ -45,7 +45,7 @@ export function computed<T>(
|
||||
}
|
||||
})
|
||||
return {
|
||||
_isRef: refSymbol,
|
||||
[refSymbol]: true,
|
||||
// expose effect so computed can be stopped
|
||||
effect: runner,
|
||||
get value() {
|
||||
|
@ -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]
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user