dispatch method

HintTransition dispatch(
  1. HintEvent event, {
  2. bool targetPresent(
    1. String targetId
    )?,
})

The single entry point. Returns the transition and applies it to the internal state.

Implementation

HintTransition dispatch(
  HintEvent event, {
  bool Function(String targetId)? targetPresent,
}) {
  final current = _state;

  // One tour at a time. In debug this is a loud contract; in release a no-op.
  if (event is HintStart && !current.isIdle) {
    assert(
      false,
      "hintful: tour '${event.tour.id}' started while $current is active"
      ' — one tour at a time',
    );
    return HintTransition(state: current, effects: const <HintEffect>[]);
  }

  final effects = <HintEffect>[];
  final next = switch (current) {
    HintIdle() => _reduceIdle(event, effects),
    HintWaiting(:final tour, :final stepIndex) =>
      _reduceWaiting(tour, stepIndex, event, effects, targetPresent),
    HintActive(:final tour, :final stepIndex) =>
      _reduceActive(tour, stepIndex, event, effects, targetPresent),
  };
  _state = next;
  return HintTransition(
    state: next,
    effects: List<HintEffect>.unmodifiable(effects),
  );
}