apply method

AggregateStateResult<TEvent, TValue, TId, TState> apply(
  1. TEvent event
)

Apply event to current state. If successful the event is added to changes and current version is incremented by 1.

Implementation

AggregateStateResult<TEvent, TValue, TId, TState> apply(TEvent event) {
  final previous = _current;
  _current = previous.when<TEvent, TState>(event);
  if (_current == previous) {
    return AggregateStateNoOp(
      _current,
    );
  }
  _changes.add(event);
  return AggregateStateResult.ok(
    current: _current,
    previous: previous,
  );
}