applyEvent method
Applies event to state and returns the next state (bead
libspiffy-mmb). state is never modified; eventador's eventHandler
replaces the aggregate's state with the result once the event has
applied, so an event that fails midway changes nothing.
Implementation
@override
InvoiceState applyEvent(InvoiceState state, Event event) {
if (event is! InvoiceEvent) {
throw ArgumentError('Expected InvoiceEvent, got ${event.runtimeType}');
}
return switch (event) {
final InvoiceCreatedEvent evt => _applyInvoiceCreated(state, evt),
// Replay-only: nothing emits InvoiceStatusChangedEvent any more
// (reachability sweep 2026-09-18, section 2). The arm stays because a
// journal written by an earlier release may contain the event and must
// still replay to the same state.
// ignore: deprecated_member_use_from_same_package
final InvoiceStatusChangedEvent evt => _applyInvoiceStatusChanged(state, evt),
final InvoicePaidEvent evt => _applyInvoicePaid(state, evt),
final InvoiceExpiredEvent evt => _applyInvoiceExpired(state, evt),
final InvoiceCancelledEvent evt => _applyInvoiceCancelled(state, evt),
_ => throw ArgumentError('Unknown event type: ${event.runtimeType}'),
};
}