Bloc: Allow for Advanced Stream Transformation

Created on 16 Apr 2019  路  1Comment  路  Source: felangel/bloc

Is your feature request related to a problem? Please describe.
Currently it is not possible to configure how events are processed by the bloc. It is only possible to filter the incoming events but the way in which they are processed is fixed (asyncExpand).

Describe the solution you'd like
transform should be able to be overridden to control how/when events are processed by mapEventToState.

  • If developers want only the latest events to be processed, they should be able to use switchMap.
@override
Stream<int> transform(events, next) {
  return (events as Observable<Event>).switchMap(next);
}
  • If developers want to process distinct events, they should be able to modify the event stream to be distinct.
@override
Stream<int> transform(events, next) {
  return super.transform(
    (events as Observable<Event>).distinct(),
    next,
  );
}

Both event filtering as well as processing should be able to be fully controlled/configured by developers while maintaining a consistent/safe default.

Additional context
Thanks to Cody and James for bringing this up 馃檹

enhancement

Most helpful comment

Published the change in bloc 0.12.0 and flutter_bloc 0.11.0 馃帀

>All comments

Published the change in bloc 0.12.0 and flutter_bloc 0.11.0 馃帀

Was this page helpful?
0 / 5 - 0 ratings