使用redux实现事务的正确方法是什么 [英] What is the correct way to implement transactions with redux

查看:79
本文介绍了使用redux实现事务的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向服务器运行两个查询,如果成功执行某些操作。没有 redux 我会这样做,使用 Q 库:

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
})

我的问题是如何使用redux完成同样的工作?我最好的猜测是我必须使用上面列出的相同方法实现中间件:

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);
    })
 }
}


推荐答案

我认为:

redux-thunk;请参阅此处的异步示例: https://github.com/gaearon/redux-thunk#motivation

redux-thunk; See the async example here: https://github.com/gaearon/redux-thunk#motivation

redux-saga
https://github.com/yelouafi/redux-saga

redux-saga https://github.com/yelouafi/redux-saga

有助于解决你的问题。

这篇关于使用redux实现事务的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆