Skip to content

Commit

Permalink
perf(effect): optimize effect trigger for array length mutation (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
guaijie authored Feb 22, 2020
1 parent e9024bf commit 76c7f54
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,18 @@ export function trigger(
}
const effects = new Set<ReactiveEffect>()
const computedRunners = new Set<ReactiveEffect>()
if (
type === TriggerOpTypes.CLEAR ||
(key === 'length' &&
isArray(target) &&
(newValue as number) < (oldValue as number))
) {
// collection being cleared or Array length mutation
if (type === TriggerOpTypes.CLEAR) {
// collection being cleared
// trigger all effects for target
depsMap.forEach(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 {
// schedule runs for SET | ADD | DELETE
if (key !== void 0) {
Expand Down

0 comments on commit 76c7f54

Please sign in to comment.