@@ -16,7 +16,7 @@ import {
16
16
toReactive ,
17
17
} from './reactive'
18
18
import type { ComputedRef } from './computed'
19
- import { TrackOpTypes , TriggerOpTypes } from './constants'
19
+ import { ReactiveFlags , TrackOpTypes , TriggerOpTypes } from './constants'
20
20
import { warn } from './warning'
21
21
22
22
declare const RefSymbol : unique symbol
@@ -40,7 +40,7 @@ export interface Ref<T = any> {
40
40
*/
41
41
export function isRef < T > ( r : Ref < T > | unknown ) : r is Ref < T >
42
42
export function isRef ( r : any ) : r is Ref {
43
- return r ? r . __v_isRef === true : false
43
+ return r ? r [ ReactiveFlags . IS_REF ] === true : false
44
44
}
45
45
46
46
/**
@@ -105,14 +105,13 @@ class RefImpl<T = any> {
105
105
106
106
dep : Dep = new Dep ( )
107
107
108
- public readonly __v_isRef = true
108
+ public readonly [ ReactiveFlags . IS_REF ] = true
109
+ public readonly [ ReactiveFlags . IS_SHALLOW ] : boolean = false
109
110
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
116
115
}
117
116
118
117
get value ( ) {
@@ -131,7 +130,9 @@ class RefImpl<T = any> {
131
130
set value ( newValue ) {
132
131
const oldValue = this . _rawValue
133
132
const useDirectValue =
134
- this . __v_isShallow || isShallow ( newValue ) || isReadonly ( newValue )
133
+ this [ ReactiveFlags . IS_SHALLOW ] ||
134
+ isShallow ( newValue ) ||
135
+ isReadonly ( newValue )
135
136
newValue = useDirectValue ? newValue : toRaw ( newValue )
136
137
if ( hasChanged ( newValue , oldValue ) ) {
137
138
this . _rawValue = newValue
@@ -277,7 +278,7 @@ class CustomRefImpl<T> {
277
278
private readonly _get : ReturnType < CustomRefFactory < T > > [ 'get' ]
278
279
private readonly _set : ReturnType < CustomRefFactory < T > > [ 'set' ]
279
280
280
- public readonly __v_isRef = true
281
+ public readonly [ ReactiveFlags . IS_REF ] = true
281
282
282
283
constructor ( factory : CustomRefFactory < T > ) {
283
284
const dep = ( this . dep = new Dep ( ) )
@@ -330,7 +331,7 @@ export function toRefs<T extends object>(object: T): ToRefs<T> {
330
331
}
331
332
332
333
class ObjectRefImpl < T extends object , K extends keyof T > {
333
- public readonly __v_isRef = true
334
+ public readonly [ ReactiveFlags . IS_REF ] = true
334
335
335
336
constructor (
336
337
private readonly _object : T ,
@@ -353,8 +354,8 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
353
354
}
354
355
355
356
class 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
358
359
constructor ( private readonly _getter : ( ) => T ) { }
359
360
get value ( ) {
360
361
return this . _getter ( )
0 commit comments