@@ -16,7 +16,7 @@ import {
1616 toReactive ,
1717} from './reactive'
1818import type { ComputedRef } from './computed'
19- import { TrackOpTypes , TriggerOpTypes } from './constants'
19+ import { ReactiveFlags , TrackOpTypes , TriggerOpTypes } from './constants'
2020import { warn } from './warning'
2121
2222declare const RefSymbol : unique symbol
@@ -40,7 +40,7 @@ export interface Ref<T = any> {
4040 */
4141export function isRef < T > ( r : Ref < T > | unknown ) : r is Ref < T >
4242export function isRef ( r : any ) : r is Ref {
43- return r ? r . __v_isRef === true : false
43+ return r ? r [ ReactiveFlags . IS_REF ] === true : false
4444}
4545
4646/**
@@ -105,14 +105,13 @@ class RefImpl<T = any> {
105105
106106 dep : Dep = new Dep ( )
107107
108- public readonly __v_isRef = true
108+ public readonly [ ReactiveFlags . IS_REF ] = true
109+ public readonly [ ReactiveFlags . IS_SHALLOW ] : boolean = false
109110
110- constructor (
111- value : T ,
112- public readonly __v_isShallow : boolean ,
113- ) {
114- this . _rawValue = __v_isShallow ? value : toRaw ( value )
115- this . _value = __v_isShallow ? value : toReactive ( value )
111+ constructor ( value : T , isShallow : boolean ) {
112+ this . _rawValue = isShallow ? value : toRaw ( value )
113+ this . _value = isShallow ? value : toReactive ( value )
114+ this [ ReactiveFlags . IS_SHALLOW ] = isShallow
116115 }
117116
118117 get value ( ) {
@@ -131,7 +130,9 @@ class RefImpl<T = any> {
131130 set value ( newValue ) {
132131 const oldValue = this . _rawValue
133132 const useDirectValue =
134- this . __v_isShallow || isShallow ( newValue ) || isReadonly ( newValue )
133+ this [ ReactiveFlags . IS_SHALLOW ] ||
134+ isShallow ( newValue ) ||
135+ isReadonly ( newValue )
135136 newValue = useDirectValue ? newValue : toRaw ( newValue )
136137 if ( hasChanged ( newValue , oldValue ) ) {
137138 this . _rawValue = newValue
@@ -277,7 +278,7 @@ class CustomRefImpl<T> {
277278 private readonly _get : ReturnType < CustomRefFactory < T > > [ 'get' ]
278279 private readonly _set : ReturnType < CustomRefFactory < T > > [ 'set' ]
279280
280- public readonly __v_isRef = true
281+ public readonly [ ReactiveFlags . IS_REF ] = true
281282
282283 constructor ( factory : CustomRefFactory < T > ) {
283284 const dep = ( this . dep = new Dep ( ) )
@@ -330,7 +331,7 @@ export function toRefs<T extends object>(object: T): ToRefs<T> {
330331}
331332
332333class ObjectRefImpl < T extends object , K extends keyof T > {
333- public readonly __v_isRef = true
334+ public readonly [ ReactiveFlags . IS_REF ] = true
334335
335336 constructor (
336337 private readonly _object : T ,
@@ -353,8 +354,8 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
353354}
354355
355356class GetterRefImpl < T > {
356- public readonly __v_isRef = true
357- public readonly __v_isReadonly = true
357+ public readonly [ ReactiveFlags . IS_REF ] = true
358+ public readonly [ ReactiveFlags . IS_READONLY ] = true
358359 constructor ( private readonly _getter : ( ) => T ) { }
359360 get value ( ) {
360361 return this . _getter ( )
0 commit comments