3

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);
    })
 }
}
Max Koretskyi
  • 85,840
  • 48
  • 270
  • 414

1 Answers1

3

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.

jthiesse
  • 332
  • 2
  • 4