我需要对服务器运行两个查询,如果成功,则执行一些操作。如果没有redux
,我会使用Q
库:
$q.all([service.doAction1(),service.doAction2()]).then(function(){
//perform some actions
})
我的问题是,使用redux应该如何做到这一点?我的最佳猜测是,我必须实现中间件,它将使用上面列出的相同方法:
function(next) {
return function(action) {
$q.all([service[action.requests[0]](),service[action.requests[1]]()]).then(function(result){
next(result);
})
}
}
我认为两者之一:
还原thunk;请参阅此处的异步示例:https://github.com/gaearon/redux-thunk#motivation
或
redux传奇https://github.com/yelouafi/redux-saga
将有助于解决您的问题。