applyEvent method

  1. @protected
WalletState applyEvent(
  1. WalletState currentState,
  2. Event event
)
inherited

Apply an event to the current state and return the new state This is the core method for event sourcing state transitions

Implementation

@protected
TState applyEvent(TState currentState, Event event) {
  final handler = _eventHandlers.getHandler(event);
  if (handler == null) {
    throw NoEventHandlerException(event);
  }

  final result = handler.process(currentState, event);
  if (result.isFailure) {
    throw EventHandlingException(event, result.errors.join(', '));
  }

  return result.newState;
}