[英]Is store.dispatch in Redux synchronous or asynchronous
I realize this is a basic question but I had no luck finding the answer elsewhere.我意识到这是一个基本问题,但我没有运气在其他地方找到答案。
Is store.dispatch
synchronous or asynchronous in Redux
?在
Redux
store.dispatch
是同步的还是异步的?
In case it is asynchronous is there a possibility to add a callback after the action has been propagated as it is possible with React
?如果它是异步的,是否有可能在操作传播后添加回调,就像
React
?
AFAIK, dispatching action is synchronous. AFAIK,调度动作是同步的。 In case if you are willing to address the asynchronous call, you can use the thunk-middleware in redux, where dispatch is provided as a callback function which you can invoke as per your convenience.
如果您愿意处理异步调用,您可以使用 redux 中的thunk-middleware ,其中 dispatch 作为回调函数提供,您可以根据自己的方便调用。 For more info, checkout this answer on SO by Author itself: How to dispatch a Redux action with a timeout?
有关更多信息,请查看作者自己在 SO 上的答案: How to dispatch a Redux action with a timeout?
Nobody knows better than the code itself .没有人比代码本身更了解。 =) As you can see
dispatch
is absolutely synchronous. =) 正如你所看到的,
dispatch
是绝对同步的。 The only warning here is that store enhancers
can (and do) substitute dispatch
method.这里唯一的警告是商店
enhancers
可以(并且确实)替代dispatch
方法。 For example, take a look at applyMiddleware
enhancer , it lets you jack middlewares in by replacing default dispatch
method with its own implementation.例如,看看
applyMiddleware
,它允许您通过用自己的实现替换默认dispatch
方法来插入中间件。 Though I never saw any Redux enhancer
which would actually remove synchronous nature of dispatch
.虽然我从未见过任何 Redux
enhancer
实际上会删除dispatch
同步性质。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.