Search code examples
reactjsfluxreactjs-flux

FLUX with multiple independent stores/dispatchers


I'm building a App with React and Flux/McFly and want to have to INDEPENDENT Stores but my McFly Actions are passed to EVERY Store i created with mcFly - despite i use seperate files to import the mcFly Instance

/stores/msg/mcfly.js:

var McFly           = require('mcfly');
,   MsgDispatcher   = new McFly()
;
module.exports = MsgDispatcher;

/stores/user/mcfly.js:

var McFly       = require('mcfly')
,   UserMcFly   = new McFly()
;
module.exports = UserMcFly;

so this should be different instances, right? But their dispatchers seems to be the same.
(?because 'flux' dispatcher is always singleton?)

When i create different Stores/ActionCreator-Pairs with different McFly "instances" every Action still goes through EVERY STORE.
i know that many people suggests to have just ONE global State/Store, but imho that approach doesn't fits to every project and i hate that behavior.

TL;DR:
Is It possible to create completely INDEPENDENT Stores/Dispatchers
or is it intended that way and WHY?
CONS: bad performance, REALLY big StateObject, checking for Updates if it isn't neccessary, Standalone SubApps not possible?, spezification of DataModels, ...

How do i create independent reuseable standalone Sub-Applications if can't have a seperated Store/Dispatcher?

best regards, Steve


Solution

  • Why is it an issue that the actions are available in all stores? You can use a switch in each store to capture the actions you are interested in for that store. Sometimes you actually want to listen to the same action in multiple stores.