When it comes to coordinating multiple sequential actions in Redux, I find it a bit confusing. I have an application with a summary panel on the left and a CRUD panel on the right. My goal is to have the app automatically update the summary after a CRUD operation. However, I also want the flexibility to refresh the summary and perform CRUD actions independently of each other. Essentially, I don't want one action to be dependent on another in the sequence. Is there a recommended way to achieve this coordination without coupling my action creators?
For instance, take a look at the thunk action creator for clearing a collection of entities (a CRUD action). Currently, it tightly integrates the fetchSummary()
dispatch.
export function clearCollection(collection) {
return function(dispatch) {
dispatch(requestCollectionClear(collection));
return doClearCollection(collection)
.then(function(coll) {
dispatch(receiveCollectionCleared(coll))
})
.then(function() {
dispatch(fetchSummary()); // <-- How do I chain actions without tight coupling?
});
// TODO: .catch()
}
}
The requestCollectionClear()
initiates the asynchronous action, while fetchSummary()
handles the subsequent step in the workflow. What's the best approach to separate fetchSummary()
from clearCollection()
, making them independent for individual use?