Reputation: 24308
I have set up a React application using Fluxxor, I am trying to use a controller view which gets multiple stores and actions, similar to this carousel example.
However in the fluxxor example it uses multiple stores but only the one set of actions. I wanted to know how to pass in multple actions.
var React = require('react/addons'),
Fluxxor = require("fluxxor"),
authorActions = require("../actions/author-actions"),
authorStore = require("../stores/author-store"),
productActions = require("../actions/product-actions"),
productStore = require("../stores/product-store");
var stores = { ProductStore: new productStore(), AuthorStore: new authorStore() };
// how do I combine my actions here?
var flux = new Fluxxor.Flux(stores, actions);
Upvotes: 2
Views: 258
Reputation: 368
To add to @BinaryMuse answer. I like to namespace my actions so there'll be no clashes on any generically named actions.
Just initiate an object with a key for each namespace:
...
var actions = { author: authorActions, product: productActions };
var flux = new Fluxxor.Flux(stores, actions);
Then call them with their namespace:
this.getFlux().actions.author.add("Aldus", "Huxley", ...);
Upvotes: 2
Reputation: 159105
Fluxxor supports adding actions dynamically:
var flux = new Fluxxor.Flux(stores);
flux.addActions(authorActions);
flux.addActions(productActions);
If the namespaces don't conflict, you can also merge them together with something like Underscore's extend:
var actions = _.extend({}, authorActions, productActions);
or Object.assign
(or a polyfill):
var actions = Object.assign({}, authorActions, productActions);
Upvotes: 2