What is the correct way to implement transactions with redux

↘锁芯ラ 提交于 2019-12-10 18:27:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!