Rematch was designed with the intention of having only one store, with the ability to update/replace reducers within the store on the fly.
However, several people have asked about using multiple stores with Redux. I believe this would lead to a better design. State management is going to change over the next few years, and its almost certainly going to result in smaller state modules.
I'd like to look into the possibility of supporting mulitple stores, and consider what changes would be necessary to make it happen.
Currently model is an import, and not recommended unless lazy loading modules.
I propose we change change model to store.model. Putting it on the store makes it clear that you're updating that particular store.
Once model is changed, it should be easy to create store as an instance. Currently is stored locally within the "redux/store.js" file, to give model access to the store.
Currently you access a particular stores dispatch through store.dispatch, so this is not a blocker.
However, there is likely to be confusion over the imported dispatch. Does it dispatch to all stores? Probably.
Similar to dispatch. Is this necessary if users already have access to the created store from init?
🤔 Aren't multiple stores the same as a single store with different sets of reducers?
Assuming reducer names don't clash, a single store with all of them, or multiple stores for each set is pretty much the same, no?
The only difference I can think of is that less listeners might get called when updating a subset store than a single store…
One underlying problem with Redux is that it gets slower at scale.
connect function must do an equality check.For the most part, most people don't have to consider any of this. Consider a good use case to be a large react-native application that must run on older devices.
If you pass the stores via the context, you can have as many stores as you like by making connect take a storeName first argument:
initialize with
<Provider stores={{store1, store2, ...}}><App/></Provider>
use with
@connect('store1', stateToProps)
class ...
Interesting. Is this an API suggestion, or does this currently work in "react-redux"?
Just a suggestion 😅 Not that hard to achieve mind you…
Closing issue as resolved once 1.0.0 leaves alpha.
Most helpful comment
One underlying problem with Redux is that it gets slower at scale.
connectfunction must do an equality check.For the most part, most people don't have to consider any of this. Consider a good use case to be a large react-native application that must run on older devices.