refactor(reactivity): make some expression simpler (#5131)
This commit is contained in:
parent
98b821d94a
commit
b9484543db
@ -125,9 +125,8 @@ function createGetter(isReadonly = false, shallow = false) {
|
||||
}
|
||||
|
||||
if (isRef(res)) {
|
||||
// ref unwrapping - does not apply for Array + integer key.
|
||||
const shouldUnwrap = !targetIsArray || !isIntegerKey(key)
|
||||
return shouldUnwrap ? res.value : res
|
||||
// ref unwrapping - skip unwrap for Array + integer key.
|
||||
return targetIsArray && isIntegerKey(key) ? res : res.value
|
||||
}
|
||||
|
||||
if (isObject(res)) {
|
||||
|
@ -26,10 +26,12 @@ function get(
|
||||
target = (target as any)[ReactiveFlags.RAW]
|
||||
const rawTarget = toRaw(target)
|
||||
const rawKey = toRaw(key)
|
||||
if (key !== rawKey) {
|
||||
!isReadonly && track(rawTarget, TrackOpTypes.GET, key)
|
||||
if (!isReadonly) {
|
||||
if (key !== rawKey) {
|
||||
track(rawTarget, TrackOpTypes.GET, key)
|
||||
}
|
||||
track(rawTarget, TrackOpTypes.GET, rawKey)
|
||||
}
|
||||
!isReadonly && track(rawTarget, TrackOpTypes.GET, rawKey)
|
||||
const { has } = getProto(rawTarget)
|
||||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive
|
||||
if (has.call(rawTarget, key)) {
|
||||
@ -47,10 +49,12 @@ function has(this: CollectionTypes, key: unknown, isReadonly = false): boolean {
|
||||
const target = (this as any)[ReactiveFlags.RAW]
|
||||
const rawTarget = toRaw(target)
|
||||
const rawKey = toRaw(key)
|
||||
if (key !== rawKey) {
|
||||
!isReadonly && track(rawTarget, TrackOpTypes.HAS, key)
|
||||
if (!isReadonly) {
|
||||
if (key !== rawKey) {
|
||||
track(rawTarget, TrackOpTypes.HAS, key)
|
||||
}
|
||||
track(rawTarget, TrackOpTypes.HAS, rawKey)
|
||||
}
|
||||
!isReadonly && track(rawTarget, TrackOpTypes.HAS, rawKey)
|
||||
return key === rawKey
|
||||
? target.has(key)
|
||||
: target.has(key) || target.has(rawKey)
|
||||
|
@ -1544,11 +1544,11 @@ function baseCreateRenderer(
|
||||
// create reactive effect for rendering
|
||||
const effect = (instance.effect = new ReactiveEffect(
|
||||
componentUpdateFn,
|
||||
() => queueJob(instance.update),
|
||||
() => queueJob(update),
|
||||
instance.scope // track it in component's effect scope
|
||||
))
|
||||
|
||||
const update = (instance.update = effect.run.bind(effect) as SchedulerJob)
|
||||
const update: SchedulerJob = (instance.update = () => effect.run())
|
||||
update.id = instance.uid
|
||||
// allowRecurse
|
||||
// #1801, #2043 component render effects should allow recursive updates
|
||||
@ -1561,7 +1561,6 @@ function baseCreateRenderer(
|
||||
effect.onTrigger = instance.rtg
|
||||
? e => invokeArrayFns(instance.rtg!, e)
|
||||
: void 0
|
||||
// @ts-ignore (for scheduler)
|
||||
update.ownerInstance = instance
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user