nid*_*idu 11 javascript flux reactjs
我正在尝试使用React与Flux架构,并偶然发现了一个我无法处理的限制.问题如下:
到目前为止,我提出的最佳解决方案是将内部调度包装起来setTimeout(f, 0),但它看起来很吓人.
实际上问题非常普遍 - 如果每个新的调度基于先前的调度处理结果,我应该如何在没有调度嵌套的情况下组织调度链(不违反当前的Flux限制).
有没有人有解决这些问题的好办法?
var selectItem(item) {
AppDispatcher.dispatch({
actionType: AppConstants.ITEM_SELECT,
item: item
});
}
// Item must be requested and selected.
// If it's in store - select it.
// Otherwise fetch and then select it.
SomeStore.dispatchToken = AppDispatcher.register((action) => {
switch(action.actionType) {
case AppConstants.ITEM_REQUESTED:
var item = SomeStore.getItem(action.itemId);
if (item) {
// Won't work because can't dispatch in the middle of dispatch
selectItem(item);
} else {
// Will work
$.getJSON(`some/${action.itemId}`, (item) => selectItem(item));
}
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1989 次 |
| 最近记录: |