问题
I need to run two queries to a server and if successful perform some action. Without redux
I'd do it like that using Q
library:
$q.all([service.doAction1(),service.doAction2()]).then(function(){
//perform some actions
})
My question is how the same should be done using redux? My best guess is that I have to implement middleware which will use the same approach listed above:
function(next) {
return function(action) {
$q.all([service[action.requests[0]](),service[action.requests[1]]()]).then(function(result){
next(result);
})
}
}
回答1:
I think either:
redux-thunk; See the async example here: https://github.com/gaearon/redux-thunk#motivation
or
redux-saga https://github.com/yelouafi/redux-saga
Would help solve your issue.
来源:https://stackoverflow.com/questions/34516484/what-is-the-correct-way-to-implement-transactions-with-redux