【发布时间】:2016-03-03 10:22:21
【问题描述】:
我正在使用flux-pattern 和flux dispatcher。在创建新的 TextItem 后,我需要将一个值从“TextStore”返回到一个操作,因为我需要在另一个商店中引用它。 这是我想做的一个非常简单的版本:
// stores.ts
var TextStore = {
add(){
// here I want to return a new ID
return createRandomID();
}
...
}
var ModuleStore = {
labelTextID; // refers to `id` on Text
...
}
// moduleactions.ts
...
import PageActions from './PageActions';
var ModuleActions = {
add: function (module) {
var textID = PageActions.add(); // here I need to get the ID of the newly create `Text`
module.labelTextID = textID;
Dispatcher.dispatch({
action: 'ADD_MODULE',
module: module
})
},
...
}
现在,当我通过调度操作添加一个新的Module 时,我还想创建一个新的Text 并从之前的商店返回其新创建的 ID。
最明显的方法是在ModuleActions 中要求TextStore 并直接调用add()。这是否违反通量模式?
有什么办法可以做到这一点,也许是承诺?通过调度程序向商店发送回调不起作用,因为当另一个调度未完成时我无法调度。
如果你们能帮助我,那就太好了!
【问题讨论】:
标签: reactjs typescript dependencies promise flux