【发布时间】:2016-01-15 05:31:15
【问题描述】:
我有几个关于redux的real-world example的问题。
-
与async example 的ajax 调用是直接使用dispatch 不同,实际示例使用中间件来处理这个问题。在 react 应用程序中使用 redux 时推荐哪种方法?为什么?
我的猜测是中间件是可重用的,所以如果需要进行多个ajax调用,只要传入不同的api路径作为参数,一个通用的ajax调用中间件就足够了。但是 dispatch 也可以这样说...
什么时候执行中间件?通过查看源代码和阅读文档,我的理解是:
dispatch an action -> all middlewares get executed , ajax calls can be made here and the returned json data can be put inside the action object and pass it onto the reducers-> reducers get executed。我说的对吗?
【问题讨论】: