简体   繁体   English

Redux 中的 store.dispatch 是同步还是异步

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

相关问题 Redux store.dispatch 目的 - Redux store.dispatch purpose Store.Dispatch() 重置 Redux Store - Store.Dispatch() Resetting Redux Store store.dispatch不是函数 - store.dispatch is not a function 'TypeError: store.dispatch is not a function' redux action testing with jest - 'TypeError: store.dispatch is not a function' redux action testing with jest 在redux中,当编写请求调度时,“ next”和“ store.dispatch”之间有什么区别? - In redux when writing thunks for dispatch, what's the difference between “next” and “store.dispatch”? 使用Redux的store.getState()和store.dispatch()进行更改而无需订阅React? - Using Redux's store.getState() and store.dispatch() to make changes without subscribing in React? 反应终极版中间件的#store.dispatch(动作)VS #next(动作) - React Redux middleware's #store.dispatch(action) vs #next(action) 当 store.dispatch(END) 出现 redux-saga 问题的下一个 js - Next js with redux-saga problem when store.dispatch(END) mapDispatchToProps与store.dispatch() - mapDispatchToProps vs. store.dispatch() 我们如何从 Redux - saga 中的 store.dispatch 返回 Promise - saga,以便我们可以等待解析然后在 SSR 中渲染? - How do we return a Promise from a store.dispatch in Redux - saga so that we can wait for the resolve and then render in SSR?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM