reduce method

The method that returns the new state.

Implementation

@override
TracingState reduce() {
  final newEvents = events.map((e) => InputEvent.fromJson(e)).toList();

  _addActionsToMap(
    events: newEvents,
    runningActions: state.runningActions,
    historicalActions: state.historicalActions,
  );

  final List<InputEvent> newList = [
    ...state.events,
    ...newEvents,
  ];

  if (newList.length > 200) {
    newList.removeRange(0, newList.length - 200);
  }

  return state.copyWith(
    events: newList,
    hasFinishedEvents: state.hasFinishedEvents ||
        newList.any((e) => e.type == InputEventType.actionFinished),
    clientDelay: state.clientDelay != 0
        ? state.clientDelay
        : DateTime.now().millisecondsSinceEpoch -
            newList.last.millisSinceEpoch,
  );
}