refactor: improve base getter readability
This commit is contained in:
parent
80e1693e1f
commit
d863ce721f
@ -60,34 +60,34 @@ function createGetter(isReadonly = false, shallow = false) {
|
|||||||
if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
|
if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
|
||||||
return Reflect.get(arrayInstrumentations, key, receiver)
|
return Reflect.get(arrayInstrumentations, key, receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = Reflect.get(target, key, receiver)
|
const res = Reflect.get(target, key, receiver)
|
||||||
|
|
||||||
if ((isSymbol(key) && builtInSymbols.has(key)) || key === '__proto__') {
|
if ((isSymbol(key) && builtInSymbols.has(key)) || key === '__proto__') {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
!isReadonly && track(target, TrackOpTypes.GET, key)
|
if (!isReadonly) {
|
||||||
|
track(target, TrackOpTypes.GET, key)
|
||||||
|
}
|
||||||
|
|
||||||
if (shallow) {
|
if (shallow) {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRef(res)) {
|
if (isRef(res)) {
|
||||||
if (targetIsArray) {
|
// ref unwrapping, only for Objects, not for Arrays.
|
||||||
return res
|
return targetIsArray ? res : res.value
|
||||||
} else {
|
|
||||||
// ref unwrapping, only for Objects, not for Arrays.
|
|
||||||
return res.value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return isObject(res)
|
if (isObject(res)) {
|
||||||
? isReadonly
|
// Convert returned value into a proxy as well. we do the isObject check
|
||||||
? // need to lazy access readonly and reactive here to avoid
|
// here to avoid invalid value warning. Also need to lazy access readonly
|
||||||
// circular dependency
|
// and reactive here to avoid circular dependency.
|
||||||
readonly(res)
|
return isReadonly ? readonly(res) : reactive(res)
|
||||||
: reactive(res)
|
}
|
||||||
: res
|
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user