I have a scenario where I feel like I need to dispatch an action in response to another action, and I don't know the best way to sort it out.
An action is dispatched in response to an HTTP response, something like:
type: 'auth'
data: { username: 'tom' }
Because that response was successful, I want to dispatch an action to send the user to the homepage:
type: 'navigate'
date: { where: 'home' }
This seems like a sensible flow to me: this thing happened, so now I want this thing to happen. Trouble is, the Flux Dispatcher doesn't allow this as we are still in the dispatch cycle. I get why dispatching while dispatching is a bad idea.
Some people have solved this with multiple dispatchers, whilst it seems that the Flux authors are sure that you only need one and that you need to rethink your stores.
I don't see how I could restructure my stores to facilitate this without obfuscating the intent. My UserStore
knows about auth
actions, and my RouteStore
knows about navigate
actions. Any suggestions on how the stores could be changed to facilitate this would be appreciated.
I feel like a setImmediate
would work, but it seems a bit dirty. I also think a dispatcher that queued actions might help but I can feel in my bones that this could cause nasty problems.
What is the best way out of this?