fluxxor为焊剂实例添加了一组以上的操作

时间:2015-04-10 01:20:12

标签: javascript reactjs flux

我已经使用Fluxxor设置了一个React应用程序,我试图使用一个控制器视图来获取多个存储和操作,类似于carousel example

然而,在fluxxor示例中,它使用多个存储但只使用一组操作。我想知道如何传递多种动作。

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

2 个答案:

答案 0 :(得分:2)

Fluxxor supports adding actions dynamically

var flux = new Fluxxor.Flux(stores);
flux.addActions(authorActions);
flux.addActions(productActions);

如果名称空间没有冲突,您也可以将它们与Underscore's extend之类的内容合并:

var actions = _.extend({}, authorActions, productActions);

Object.assign(或polyfill):

var actions = Object.assign({}, authorActions, productActions);

答案 1 :(得分:2)

添加到@BinaryMuse答案。我喜欢命名我的行为,因此任何通用名称的行动都不会发生冲突。

只需使用每个命名空间的键启动一个对象:

...
var actions = { author: authorActions, product: productActions  };
var flux = new Fluxxor.Flux(stores, actions);

然后用他们的命名空间调用它们:

this.getFlux().actions.author.add("Aldus", "Huxley", ...);