@@ -44,9 +44,11 @@ export function shallowRef(value?: unknown) {
44
44
return createRef ( value , true )
45
45
}
46
46
47
- class _Ref < T > {
47
+ class RefImpl < T > {
48
48
private _value : T
49
49
50
+ public readonly __v_isRef = true
51
+
50
52
constructor ( private _rawValue : T , private readonly _shallow = false ) {
51
53
this . _value = _shallow ? _rawValue : convert ( _rawValue )
52
54
}
@@ -63,17 +65,13 @@ class _Ref<T> {
63
65
trigger ( toRaw ( this ) , TriggerOpTypes . SET , 'value' , newVal )
64
66
}
65
67
}
66
-
67
- get __v_isRef ( ) {
68
- return true
69
- }
70
68
}
71
69
72
70
function createRef ( rawValue : unknown , shallow = false ) {
73
71
if ( isRef ( rawValue ) ) {
74
72
return rawValue
75
73
}
76
- return new _Ref ( rawValue , shallow )
74
+ return new RefImpl ( rawValue , shallow )
77
75
}
78
76
79
77
export function triggerRef ( ref : Ref ) {
@@ -113,10 +111,12 @@ export type CustomRefFactory<T> = (
113
111
set : ( value : T ) => void
114
112
}
115
113
116
- class _CustomRef < T > {
114
+ class CustomRefImpl < T > {
117
115
private readonly _get : ReturnType < CustomRefFactory < T > > [ 'get' ]
118
116
private readonly _set : ReturnType < CustomRefFactory < T > > [ 'set' ]
119
117
118
+ public readonly __v_isRef = true
119
+
120
120
constructor ( factory : CustomRefFactory < T > ) {
121
121
const { get, set } = factory (
122
122
( ) => track ( this , TrackOpTypes . GET , 'value' ) ,
@@ -133,14 +133,10 @@ class _CustomRef<T> {
133
133
set value ( newVal ) {
134
134
this . _set ( newVal )
135
135
}
136
-
137
- get __v_isRef ( ) {
138
- return true
139
- }
140
136
}
141
137
142
138
export function customRef < T > ( factory : CustomRefFactory < T > ) : Ref < T > {
143
- return new _CustomRef ( factory ) as any
139
+ return new CustomRefImpl ( factory ) as any
144
140
}
145
141
146
142
export function toRefs < T extends object > ( object : T ) : ToRefs < T > {
@@ -154,7 +150,9 @@ export function toRefs<T extends object>(object: T): ToRefs<T> {
154
150
return ret
155
151
}
156
152
157
- class _ObjectRef < T extends object , K extends keyof T > {
153
+ class ObjectRefImpl < T extends object , K extends keyof T > {
154
+ public readonly __v_isRef = true
155
+
158
156
constructor ( private readonly _object : T , private readonly _key : K ) { }
159
157
160
158
get value ( ) {
@@ -164,17 +162,13 @@ class _ObjectRef<T extends object, K extends keyof T> {
164
162
set value ( newVal ) {
165
163
this . _object [ this . _key ] = newVal
166
164
}
167
-
168
- get __v_isRef ( ) {
169
- return true
170
- }
171
165
}
172
166
173
167
export function toRef < T extends object , K extends keyof T > (
174
168
object : T ,
175
169
key : K
176
170
) : Ref < T [ K ] > {
177
- return new _ObjectRef ( object , key ) as any
171
+ return new ObjectRefImpl ( object , key ) as any
178
172
}
179
173
180
174
// corner case when use narrows type
0 commit comments