【发布时间】:2015-12-06 17:39:33
【问题描述】:
案例是我通过点击操作向我的用户添加一个新项目。添加项目后,ActiveItemStore 将被更新,然后我想导航到活动项目。但目前在 Store 更新之前调用转换。
当前代码:
var actionListener = new ActionListeners(alt);
var listenerRef = actionListener.addActionListener(MyItemActions.ADDED,
function() {
setTimeout(function() { // Fixes Cannot dispatch in the middle of a dispatch.
this.transitionTo('active-item', {locale: user.locale});
// will be called before the ActiveItemStore is updated
});
}.bind(this));
actionListener.removeActionListener(listenerRef);
}.bind(this));
// call action
MyItemActions.add({
id: item.id,
active: true
});
在这种情况下我是否需要使用waitFor 或最佳实践是什么,以及如何避免在没有 setTimeout 的情况下分派?
【问题讨论】:
标签: javascript reactjs reactjs-flux flux react-alt