Single dispatch for multiple stores with redux-middleware
See original GitHub issueI have an app that currently use a Flux architecture with a single dispatcher and multiple stores that reacts to an action. I want to rewrite it with zustand but I’m not sure how to re-create this pattern. So basically I want multiple stores with reducer that react to an action, and one action is dispatched to every reducer in stores.
I created a simple exemple of my attempt here
The main thing here is
const dispatch = (...args) => {
apiA.dispatch(...args);
apiB.dispatch(...args);
}
I have a single dispatch function that will dispatch to every stores. This works great but is there a better way to handle it with zustand ? Or is zustand not made for this kind of architecture ?
Maybe my answer is the combine
function, but I’m not sure how to implement it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Redux FAQ: Store Setup
Is it OK to have more than one middleware chain in my store enhancer? What is the difference between next and dispatch in...
Read more >Where to dispatch multiple actions in redux? - Stack Overflow
If the second dispatch depends on the actions of first dispatch, you can get the state from the store, check if it satisfies...
Read more >Create Redux Middleware to Dispatch Multiple Actions
We only have a few dispatching functions that need to be known by our React Application. Each one actually has multiple actions that...
Read more >Javascript: Redux: Dispatching Multiple Actions - Medium
Probably one of the first things anyone starting out on Redux wonders is, can you dispatch multiple actions? The answer of course is,...
Read more >Can I dispatch multiple actions from Redux action creators?
Actually, this is a trick question; with the appropriate store middleware, it is possible to do both at once! How does this work?...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, I found a way to achieve what I wanted, I’ve kept my reducer synchronous as described in the doc. And for the action where I need to run asynchronous, I do not use the returned value from reducer but I use the
setState()
function. I’m closing this issue, thanks for the help @dai-shiSo, it’s like locking store updates. A naive way would be like this?
Not very confident if this works without pitfalls, though, depending on usage.