-
Notifications
You must be signed in to change notification settings - Fork 149
Trigger this.emit( 'change' ); after dispatch ends #92
Copy link
Copy link
Closed
Description
I'm using Fluxxor + rackt/react-router and running into the "Cannot dispatch an action (...) while another action (...) is being dispatched" error.
Here's what I'm doing:
- A Login route/component displays a login form
- onSubmit triggers the "login" action creator.
- The "login" action creator interacts (async) with our API to validate the submission. When the call completes, dispatch the "LOGIN_SUCCESS" action (assume no failures for simplicity)
- AuthStore is listening for this action and updates its data and triggers an
this.emit( 'change' ); - The Login route/component is using
StoreWatchMixin( 'AuthStore' )to listen for updates and uses react-router totransitionTo( 'dashboard' ) - During its setup, the "dashboard" route/component triggers an action.
- The "Cannot dispatch an action..." error is thrown.
The problem is that the emit call triggers the transition and results in the "dashboard" component set up while the dispatcher thinks that the "LOGIN_SUCCESS" action is still being fired.
Is there a way to defer the emit call to after the action dispatch is complete? Or should I be thinking of another approach to this? (I could do a setTimeout but that feels fragile.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels