简体   繁体   English

使用redux实现事务的正确方法是什么

[英]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: 没有redux我会像使用Q库那样做:

$q.all([service.doAction1(),service.doAction2()]).then(function(){
    //perform some actions
})

My question is how the same should be done using redux? 我的问题是如何使用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);
    })
 }
}

I think either: 我想要么:

redux-thunk; 终极版,形实转换; See the async example here: https://github.com/gaearon/redux-thunk#motivation 请参阅此处的异步示例: https//github.com/gaearon/redux-thunk#motivation

or 要么

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

Would help solve your issue. 有助于解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这是在Redux中实现中间件的正确方法吗? - Is this the correct way to implement middleware in redux? 在淘汰赛中实现无限滚动的正确方法是什么? - What is the correct way to implement infinite scroll in knockout? Redux:在reducer 中过滤数据数组的正确方法是什么? - Redux: what is the correct way to filter a data array in reducer? 使用 redux 和 react 时渲染条件 jsx 的正确方法是什么 - What is correct way to render conditional jsx when using redux with react 在Redux / React组件中更改props值的正确方法是什么? - What's the correct way to mutate props value in Redux/React components? 通过Redux Store Enhancer添加其他中间件的正确方法是什么? - What is the correct way to add additional middleware through a redux store enhancer? 使用 redux observable 和 firebase 执行异步操作的正确方法是什么? - What is the correct way to do an async action using redux observable and firebase? 在Javascript中实现解耦代码/回调的正确方法是什么? - What is the correct way to implement decoupled code / callbacks in Javascript? 正确的实施搜索方式? - Correct way to implement search? 这是实现cookie的正确方法吗? - Is this the correct way to implement a cookie?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM