mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.22k stars 139 forks source link

Dispatching action in effect - running orders #472

Closed alperenbelgic closed 3 months ago

alperenbelgic commented 4 months ago

I dispatch LoginSubmittedAction in a component, and in the effect method I dispatch LoginAction.

I was expecting to see

login action dispatch completed

log woud be written as last log. but it works before LoginAction's reducer and effect.

is this the expected behaviour?

( the reason I have multipe actions is that I'd like to isolate the behaviour in LoginAction to reuse somewhere else.

image

image

stagep commented 4 months ago

It appears that you are dispatching to an effect within an effect so essentially calling an async method within an async method. There is no guarantee of order because the async method called from your async method could complete before or after the next line of code. Use an effect for calling an async method like an API and then dispatch an action that is handled by a reducer and updates the state.