[英]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.