Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to implement transactions with redux

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);
    })
 }
}
like image 398
Max Koretskyi Avatar asked Oct 15 '25 17:10

Max Koretskyi


1 Answers

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.

like image 198
jthiesse Avatar answered Oct 17 '25 05:10

jthiesse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!