Bloc: Bloc not calling super unless yield* is used

Created on 27 Nov 2020  路  3Comments  路  Source: felangel/bloc

Describe the bug
Hello and thanks for the time in answering this question!
I've created BLoC_A. Let's say that we have two other BLoCs that extend it (as they have mutual shared logic, and I decided
for the sake of brevity not to use composition).

When calling super.mapEventToState it seems like nothing happens, but when calling it with yield*, all of a sudden it works.

I'm wondering why this happens and if anyone has any insight into this issue

To Reproduce
Steps to reproduce the behavior:

  1. Inherit from any BLoC that has mapEventToState logic
  2. Call super.mapEventToState in the child BLoC.
  3. Debug and see that nothing happens.

Expected behavior
Super is called as usual.

question

All 3 comments

Hi @dorsamet 馃憢
Thanks for opening an issue!

You should not call super.mapEventToState because it returns a stream and must constantly be processing the incoming events. Yield* processes all data on the stream until the stream is closed which is why it works in that case.

Hope that helps 馃憤

The super method is an abstract method. And it should be implemented by the subclass in order to map incoming events to states. Since the return type is Stream you have to use yield to generate(emit) a new state. Please check the official doc about streams.

The super method is an abstract method. And it should be implemented by the subclass in order to map incoming events to states. Since the return type is Stream you have to use yield to generate(emit) a new state. Please check the official doc about streams.

Actually the super method here does have some logic and is not abstract, but I do understand the added complexity with using streams. Maybe it might be a good idea to not do that.
With that said, the super method may actually generate a new state so yield* makes sense to actually be the route to go. I was more wondering why the code was not executed to begin with

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wheel1992 picture wheel1992  路  3Comments

clicksocial picture clicksocial  路  3Comments

frankrod picture frankrod  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

komapeb picture komapeb  路  3Comments