felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.8k stars 3.39k forks source link

feat: Add emitForEach / emitOnEach Methods (or something similar) to Cubit #3555

Open jtdLab opened 2 years ago

jtdLab commented 2 years ago

Description

When working with a Cubit that consume some other Stream you need to maintain a StreamSubscription during the life of the Cubit and close it etc. This comes with some extra work which is handled well in Bloc via emit.forEach / emit.onEach but no similar solution exists for that when using Cubit.

Desired Solution

Adding the methods emitForEach and emitOnEach with same signatures and functionality as their counter part in Emitter.

Alternatives Considered

Maybe give a Cubit its own Emitter.

jyardin commented 1 year ago

I think the alternative solution you proposed of exposing an Emitter would be better, as it would give a more consistent experience between Bloc and Cubit.

It would be even cooler if the Emitter is returned by an emit property, replacing the emit(State) method.
It would be a breaking change, not sure how big a breaking change though, as the main usage of emit (just calling emit(newState)) would still work as intended.

vgtle commented 1 year ago

This would be a great feature. Are there any plans of implementing this? Or any ways to contribute to this?