Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flux Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch

Tags:

My code https://gist.github.com/ButuzGOL/707d1605f63eef55e4af

So when I get sign-in success callback I want to make redirect,
redirect works through dispatcher too.

And I am getting Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.

Is there any hack to call action in the middle ?

like image 997
ButuzGOL Avatar asked Oct 27 '14 05:10

ButuzGOL


People also ask

What is dispatcher in flux?

The dispatcher is the central hub that manages all data flow in a Flux application. It is essentially a registry of callbacks into the stores and has no real intelligence of its own — it is a simple mechanism for distributing the actions to the stores. Each store registers itself and provides a callback.

What is likely to happen in Reactjs flux when a dispatch is triggered and the store gets updated?

Stores get updated because they have a callback that is registered using the dispatcher. Node's event emitter is used to update the store and broadcast the update to view. The view never directly updates the application state. It is updated because of the changes to the store.


1 Answers

I don't see where in the gist that you posted you are doing the redirect. I only see the AUTH_SIGNIN and AUTH_SIGNIN_SUCCESS actions, and they look pretty straightforward.

But no, there is no hack to create an action in the middle of a dispatch, and this is by design. Actions are not supposed to be things that cause a change. They are supposed to be like a newspaper that informs the application of a change in the outside world, and then the application responds to that news. The stores cause changes in themselves. Actions just inform them.

If you have this error, then you need to back up and look at how you're handling the original action. Most often, you can set up your application to respond to the original action, accomplish everything you need to do, and avoid trying to create a second action.

like image 94
fisherwebdev Avatar answered Sep 21 '22 06:09

fisherwebdev