( aggregateValue: AggregateValue | undefined, oldLength: number, newValues: IdMap<Value | undefined>, changedValues: Coll<[Value | undefined, Value | undefined]>, aggregators: Aggregators<Value, AggregateValue>, force = false, )
| 74 | ]); |
| 75 | |
| 76 | export const getAggregateValue = <Value, AggregateValue>( |
| 77 | aggregateValue: AggregateValue | undefined, |
| 78 | oldLength: number, |
| 79 | newValues: IdMap<Value | undefined>, |
| 80 | changedValues: Coll<[Value | undefined, Value | undefined]>, |
| 81 | aggregators: Aggregators<Value, AggregateValue>, |
| 82 | force = false, |
| 83 | ) => { |
| 84 | if (collIsEmpty(newValues)) { |
| 85 | return undefined; |
| 86 | } |
| 87 | |
| 88 | const [aggregate, aggregateAdd, aggregateRemove, aggregateReplace] = |
| 89 | aggregators; |
| 90 | force ||= isUndefined(aggregateValue); |
| 91 | collForEach(changedValues, ([oldValue, newValue]) => { |
| 92 | if (!force) { |
| 93 | aggregateValue = isUndefined(oldValue) |
| 94 | ? aggregateAdd?.( |
| 95 | aggregateValue as AggregateValue, |
| 96 | newValue as Value, |
| 97 | oldLength++, |
| 98 | ) |
| 99 | : isUndefined(newValue) |
| 100 | ? aggregateRemove?.( |
| 101 | aggregateValue as AggregateValue, |
| 102 | oldValue, |
| 103 | oldLength--, |
| 104 | ) |
| 105 | : aggregateReplace?.( |
| 106 | aggregateValue as AggregateValue, |
| 107 | newValue, |
| 108 | oldValue, |
| 109 | oldLength, |
| 110 | ); |
| 111 | force ||= isUndefined(aggregateValue); |
| 112 | } |
| 113 | }); |
| 114 | |
| 115 | return force |
| 116 | ? aggregate(collValues(newValues) as Value[], collSize(newValues)) |
| 117 | : aggregateValue; |
| 118 | }; |
no test coverage detected
searching dependent graphs…