Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call dispatch while another dispatch is executing #48

Closed
jolafrite opened this issue Aug 15, 2015 · 2 comments
Closed

Cannot call dispatch while another dispatch is executing #48

jolafrite opened this issue Aug 15, 2015 · 2 comments

Comments

@jolafrite
Copy link

Hi,

I'm facing a lots of dispatch overlap issues.
My basic scenario is :
When the the project is initialized,
1- it loads the current user (if the client has a token) (it dispatches LOAD_USER, LOAD_USER_SUCCESS, LOAD_USER_ERROR)
2- The user store listens to LOAD_USER_SUCCESS, sets the user and emits a users.load_user.success
3- My App component listens to users.load_user.success and calls the action to initialize the router.
4- The router dispatches CHANGE_ROUTE, CHANGE_ROUTE_SUCCESS and CHANGE_ROUTE_ERROR

The problem is the dispatcher did not finish to dispatch LOAD_USER_SUCCESS and triggers CHANGE_ROUTE.

You never really talked about implementing a queue of dispatch, is there a reason for that ?

ps. I saw someone proposed to implement the possibility to $listenTo multiple events, what is the status ?

@christianalfoni
Copy link
Owner

Hi @jolafrite ,

This is a typical FLUX issue. There has been a lot of progress on FLUX and if you take a look at: www.christianalfoni.com/cerebral you can check out my latest project which handles all this stuff a lot better. It also gives some pretty amazing possibilities with the debugger.

So FLUX works very well, it has solved a lot of issues, but it has also introduced some new, like what you are experiencing here. So yeah, the community is moving a long and introducing suggestions to fixing these issues.

@jrust
Copy link
Collaborator

jrust commented Nov 18, 2015

As @christianalfoni said this is a problem that is generic to the flux architecture. The primary way I have seen it solved is by having an action dispatch multiple events, e.g.:

function loadUserAndRoute() {
 flux.dispatch('LOAD_USER_SUCCESS');
  user.load().then(() => {
    flux.dispatch('LOAD_USER_SUCCESS');
    changeRoute();
  });
}

function changeRoute() {
  flux.dispatch('CHANGE_ROUTE');
}

The basic idea being that your actions are the place where you chain multiple actions together. The listeners are always only for syncing data from stores to the view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants