1
1
import { isTracking , trackEffects , triggerEffects } from './effect'
2
2
import { TrackOpTypes , TriggerOpTypes } from './operations'
3
- import { isArray , isObject , hasChanged } from '@vue/shared'
4
- import { reactive , isProxy , toRaw , isReactive } from './reactive'
3
+ import { isArray , hasChanged } from '@vue/shared'
4
+ import { isProxy , toRaw , isReactive , toReactive } from './reactive'
5
5
import { CollectionTypes } from './collectionHandlers'
6
6
import { createDep , Dep } from './dep'
7
7
@@ -60,9 +60,6 @@ export function triggerRefValue(ref: RefBase<any>, newVal?: any) {
60
60
}
61
61
}
62
62
63
- const convert = < T extends unknown > ( val : T ) : T =>
64
- isObject ( val ) ? reactive ( val ) : val
65
-
66
63
export function isRef < T > ( r : Ref < T > | unknown ) : r is Ref < T >
67
64
export function isRef ( r : any ) : r is Ref {
68
65
return Boolean ( r && r . __v_isRef === true )
@@ -84,6 +81,13 @@ export function shallowRef(value?: unknown) {
84
81
return createRef ( value , true )
85
82
}
86
83
84
+ function createRef ( rawValue : unknown , shallow : boolean ) {
85
+ if ( isRef ( rawValue ) ) {
86
+ return rawValue
87
+ }
88
+ return new RefImpl ( rawValue , shallow )
89
+ }
90
+
87
91
class RefImpl < T > {
88
92
private _value : T
89
93
private _rawValue : T
@@ -93,7 +97,7 @@ class RefImpl<T> {
93
97
94
98
constructor ( value : T , public readonly _shallow : boolean ) {
95
99
this . _rawValue = _shallow ? value : toRaw ( value )
96
- this . _value = _shallow ? value : convert ( value )
100
+ this . _value = _shallow ? value : toReactive ( value )
97
101
}
98
102
99
103
get value ( ) {
@@ -105,19 +109,12 @@ class RefImpl<T> {
105
109
newVal = this . _shallow ? newVal : toRaw ( newVal )
106
110
if ( hasChanged ( newVal , this . _rawValue ) ) {
107
111
this . _rawValue = newVal
108
- this . _value = this . _shallow ? newVal : convert ( newVal )
112
+ this . _value = this . _shallow ? newVal : toReactive ( newVal )
109
113
triggerRefValue ( this , newVal )
110
114
}
111
115
}
112
116
}
113
117
114
- function createRef ( rawValue : unknown , shallow : boolean ) {
115
- if ( isRef ( rawValue ) ) {
116
- return rawValue
117
- }
118
- return new RefImpl ( rawValue , shallow )
119
- }
120
-
121
118
export function triggerRef ( ref : Ref ) {
122
119
triggerRefValue ( ref , __DEV__ ? ref . value : void 0 )
123
120
}
0 commit comments