on<T> method

  1. @mustCallSuper
EventBusSubscriber on<T>(
  1. EventBusSubscriber<T> processor, {
  2. bool reactsToPause = false,
  3. bool firesAfterResume = true,
})

Subscribes to event of given type

Adds subscriber to local subscribers collection

processor - function that handles event reactsToPause - flag indicating that this handler is paused when assosiated view is paused firesAfterResume - flag indicating that events that are received while pause need to be replayed

Implementation

@mustCallSuper
EventBusSubscriber on<T>(
  EventBusSubscriber<T> processor, {
  bool reactsToPause = false,
  bool firesAfterResume = true,
}) {
  void dynamicProcessor(event) {
    if (UMvvmApp.isInTestMode) {
      _receivedEvents.add(event.runtimeType);

      _testReceivedEventsController.add(event);
    }

    if (reactsToPause && isPaused) {
      if (firesAfterResume) {
        _eventsReceivedWhilePaused.add(event);
      }

      return;
    }

    processor(event as T);
  }

  _subscribers[T] = dynamicProcessor;

  return dynamicProcessor;
}