Search code examples
javascriptreactjsflux

fluxxor add more than 1 set of actions to a flux instance


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);

Solution

  • 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);