Bloc: Direct transition to specific state

Created on 14 May 2020  路  6Comments  路  Source: felangel/bloc

business require sometimes transition to specific state without dispatching event .
as example if user logout ,
authentication bloc can start the process of logging out with server and yiel to the corresponding state
while user information bloc which caches the data locally can , can directly yiel to its initial state without dispatching new event , or disposing the old bloc and recreating it again

question

Most helpful comment

@MoSamir reverting to a previous state is logic haha 馃槢

All 6 comments

Hi @MoSamir 馃憢
Thanks for opening an issue!

I鈥檓 not sure I understand the question. You can yield a state immediate without waiting for an asynchronous process to finish.

@felangel thanks for quick response ,
but my question is more related to something like
blocInstance.moveToState(state)

directly from anywhere in the UI or any other layer without the need to dispatch event then handle this event and yeil to the state in mapEventToState

@MoSamir that violates the whole paradigm. The only way to update a bloc鈥檚 state is by adding an event. Otherwise you鈥檙e allowing the UI to know about how to go from one bloc state to another (business logic). The UI should not know about the logic of how to go from one state to another.

@felangel well it make sense for sure ,I was trying to find a way to revert back to previous state without adding additional non-logic events

@MoSamir there's also onTransition which you can override for some fancy stuff 馃かAlthough I completely agree with @felangel that events should be in charge of triggering state changes.

@MoSamir reverting to a previous state is logic haha 馃槢

Was this page helpful?
0 / 5 - 0 ratings

Related issues

komapeb picture komapeb  路  3Comments

Reidond picture Reidond  路  3Comments

MahdiPishguy picture MahdiPishguy  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

timtraversy picture timtraversy  路  3Comments