fluxxor 向 flux 实例添加多于一组的操作
fluxxor add more than 1 set of actions to a flux instance
我已经使用 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);
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);
添加到@BinaryMuse 答案。我喜欢为我的操作命名空间,这样任何通用命名的操作都不会发生冲突。
只需为每个命名空间启动一个带有键的对象:
...
var actions = { author: authorActions, product: productActions };
var flux = new Fluxxor.Flux(stores, actions);
然后用它们的命名空间调用它们:
this.getFlux().actions.author.add("Aldus", "Huxley", ...);
我已经使用 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);
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);
添加到@BinaryMuse 答案。我喜欢为我的操作命名空间,这样任何通用命名的操作都不会发生冲突。
只需为每个命名空间启动一个带有键的对象:
...
var actions = { author: authorActions, product: productActions };
var flux = new Fluxxor.Flux(stores, actions);
然后用它们的命名空间调用它们:
this.getFlux().actions.author.add("Aldus", "Huxley", ...);