reduce method
Fold a message into the registry's keyed collection and return the NEXT
collection. PURE — replay depends on it; no side effects, no clocks.
A message may touch MANY entries (a batch load) or none. The
identifiable map extensions keep it terse:
entities.upsert(x) · entities.upsertAll(xs) · entities.removeById(id)
· entities.updateById(id, (cur) => …).
Implementation
@override
IdentifiableMap<Object, SendPhase> reduce(
IdentifiableMap<Object, SendPhase> entities,
StageMsg msg,
) => switch (msg) {
// A new send calls every other one in the air home.
SendDisplaced(:final send) => {
for (final e in entities.values)
if (e.tag != send.tag)
e.tag: e.state == .sending || e.state == .parked
? SendPhase(e.tag, .returning)
: e,
send.tag: SendPhase(send.tag, .sending),
},
SendArrived(:final tag) => entities.upsert(SendPhase(tag, .parked)),
SendsRecalled(:final tag?) => entities.containsKey(tag)
? entities.upsert(SendPhase(tag, .returning))
: entities,
SendsRecalled(:final except) => {
for (final e in entities.values)
e.tag: e.tag == except ? e : SendPhase(e.tag, .returning),
},
SendGone(:final tag) => entities.removeById(tag),
FlightLanded(flight: Flight(kind: .dismissing || .effect)) =>
entities.isEmpty ? entities : const {},
FlightLanded() ||
StageTaken() ||
ModeSet() ||
OriginPointed() ||
OriginMeasured() ||
WidgetShown() ||
AspectRatioSet() ||
BackgroundSet() ||
GestureBuilderSet() ||
OnEndSet() ||
FlightTook() ||
InteractionBegan() ||
InteractionEnded() ||
OriginGestureSet() ||
HybridDrivingSet() =>
entities,
};