perf(effect): optimize effect trigger for array length mutation (#761)
This commit is contained in:
parent
e9024bf1b7
commit
76c7f54269
@ -176,17 +176,18 @@ export function trigger(
|
|||||||
}
|
}
|
||||||
const effects = new Set<ReactiveEffect>()
|
const effects = new Set<ReactiveEffect>()
|
||||||
const computedRunners = new Set<ReactiveEffect>()
|
const computedRunners = new Set<ReactiveEffect>()
|
||||||
if (
|
if (type === TriggerOpTypes.CLEAR) {
|
||||||
type === TriggerOpTypes.CLEAR ||
|
// collection being cleared
|
||||||
(key === 'length' &&
|
|
||||||
isArray(target) &&
|
|
||||||
(newValue as number) < (oldValue as number))
|
|
||||||
) {
|
|
||||||
// collection being cleared or Array length mutation
|
|
||||||
// trigger all effects for target
|
// trigger all effects for target
|
||||||
depsMap.forEach(dep => {
|
depsMap.forEach(dep => {
|
||||||
addRunners(effects, computedRunners, dep)
|
addRunners(effects, computedRunners, dep)
|
||||||
})
|
})
|
||||||
|
} else if (key === 'length' && isArray(target)) {
|
||||||
|
depsMap.forEach((dep, key) => {
|
||||||
|
if (key === 'length' || key >= (newValue as number)) {
|
||||||
|
addRunners(effects, computedRunners, dep)
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// schedule runs for SET | ADD | DELETE
|
// schedule runs for SET | ADD | DELETE
|
||||||
if (key !== void 0) {
|
if (key !== void 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user