transformEvents method

  1. @Deprecated('Use `on<Event>` with an `EventTransformer` instead. ' 'Will be removed in v8.0.0')
Stream<Transition<MeEvent, MeState>> transformEvents(
  1. Stream<MeEvent> events,
  2. TransitionFunction<MeEvent, MeState> transitionFn
)
inherited

@Deprecated - Use on<Event> with an EventTransformer instead. Will be removed in v8.0.0

Transforms the events stream along with a transitionFn function into a Stream<Transition>. Events that should be processed by mapEventToState need to be passed to transitionFn. By default asyncExpand is used to ensure all events are processed in the order in which they are received. You can override transformEvents for advanced usage in order to manipulate the frequency and specificity with which mapEventToState is called as well as which events are processed.

For example, if you only want mapEventToState to be called on the most recent Event you can use switchMap instead of asyncExpand.

@override
Stream<Transition<Event, State>> transformEvents(events, transitionFn) {
  return events.switchMap(transitionFn);
}

Alternatively, if you only want mapEventToState to be called for distinct events:

@override
Stream<Transition<Event, State>> transformEvents(events, transitionFn) {
  return super.transformEvents(
    events.distinct(),
    transitionFn,
  );
}

Implementation

@Deprecated(
  'Use `on<Event>` with an `EventTransformer` instead. '
  'Will be removed in v8.0.0',
)
Stream<Transition<Event, State>> transformEvents(
  Stream<Event> events,
  TransitionFunction<Event, State> transitionFn,
) {
  return events.asyncExpand(transitionFn);
}