on<E extends Event> method
void
on<E extends Event>(
- _HandlerFn<
E, State> fn
Register an event handler for an event of type E
.
There should only ever be one event handler per event type E
.
Implementation
void on<E extends Event>(
_HandlerFn<E, State> fn,
) {
final registered = _handlers.any((handler) => handler.type == E);
assert(
!registered,
'on<$E> was called multiple times.', // coverage:ignore-line
);
_handlers.add(
_Handler(
isType: (e) => e is E,
type: E,
fn: fn,
),
);
}