Closed FoxxMD closed 9 years ago
Difficult to tell from your code what the issue is but I'd recommend against invoking actions as a result of another action. A different approach which is a bit more in keeping with the flux architecture would be to have the store that listens to the ADD_NOTIFICATION
action to instead listen to ADD_MERCHANT
and UPDATE_MERCHANT
but use waitFor to wait for the merchant store to update before querying it.
var NotificationsStore = Marty.createStore({
handlers: {
addMerchantAddedNotification: MerchantConstants.ADD_MERCHANT,
addMerchantUpdatedNotification: MerchantConstants.UPDATE_MERCHANT
},
addMerchantAddedNotification: function () {
this.waitFor(MerchantStore);
var status = MerchantStore.getState().status;
if (status === 'SUCCESS') {
...
}
},
addMerchantUpdatedNotification: function () {
this.waitFor(MerchantStore);
var status = MerchantStore.getState().status;
if (status === 'SUCCESS') {
...
}
}
})
I am receiving the error
Uncaught Error: Invariant Violation: Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.
when trying to perform an action but under almost identical conditions performing another action never receive this. I'm hoping someone can shed some light on what I'm missing...I will describe both actions in parallel.
Action creator is called
new.jsx
details.jsx
Action creator calls source and clears 'status' state in store
Source calls api and then calls source action creator
Source action creator dispatches to store
Store updates state and notifies of changes, then calls to update status
Finally, components update and another action creator is invoked
new.jsx
details.jsx
As you can see the flow for both of these use cases are very similar. This is because right now they basically do the same thing, however I plan on adding more functionality to both as I develop the app. But when
new.jsx
does its thing I get the error -- and never receive it when usingdetail.jsx
.What am I missing??