@@ -36,7 +36,8 @@ const arrayInstrumentations: Record<string, Function> = {}
36
36
37
37
function createGetter ( isReadonly = false , shallow = false ) {
38
38
return function get ( target : object , key : string | symbol , receiver : object ) {
39
- if ( isArray ( target ) && hasOwn ( arrayInstrumentations , key ) ) {
39
+ const targetIsArray = isArray ( target )
40
+ if ( targetIsArray && hasOwn ( arrayInstrumentations , key ) ) {
40
41
return Reflect . get ( arrayInstrumentations , key , receiver )
41
42
}
42
43
const res = Reflect . get ( target , key , receiver )
@@ -48,18 +49,24 @@ function createGetter(isReadonly = false, shallow = false) {
48
49
// TODO strict mode that returns a shallow-readonly version of the value
49
50
return res
50
51
}
51
- // ref unwrapping, only for Objects, not for Arrays.
52
- if ( isRef ( res ) && ! isArray ( target ) ) {
53
- return res . value
52
+ if ( isRef ( res ) ) {
53
+ if ( targetIsArray ) {
54
+ track ( target , TrackOpTypes . GET , key )
55
+ return res
56
+ } else {
57
+ // ref unwrapping, only for Objects, not for Arrays.
58
+ return res . value
59
+ }
60
+ } else {
61
+ track ( target , TrackOpTypes . GET , key )
62
+ return isObject ( res )
63
+ ? isReadonly
64
+ ? // need to lazy access readonly and reactive here to avoid
65
+ // circular dependency
66
+ readonly ( res )
67
+ : reactive ( res )
68
+ : res
54
69
}
55
- track ( target , TrackOpTypes . GET , key )
56
- return isObject ( res )
57
- ? isReadonly
58
- ? // need to lazy access readonly and reactive here to avoid
59
- // circular dependency
60
- readonly ( res )
61
- : reactive ( res )
62
- : res
63
70
}
64
71
}
65
72
0 commit comments