eventHandler method

  1. @override
void eventHandler(
  1. Event event
)
inherited

Apply an event to update the aggregate state This is called during both command processing and recovery

Implementation

@override
void eventHandler(Event event) {
  try {
    // Initialize state if needed
    if (!isInitialized) {
      _currentState = createInitialState();
    }

    // Apply the event to get new state
    final newState = applyEvent(currentState, event);

    // Update current state
    _currentState = newState;

    // Call event application hook
    onEventApplied(event, newState);
  } catch (e) {
    onEventApplicationFailure(event, e);
    rethrow;
  }
}