简体   繁体   English

Redux中间件和Redux可观察的史诗有什么区别?

[英]What is the difference between a redux middleware and a redux-observable epic?

I would like to understand when it is appropriate to use a redux middleware over a redux-observable epic (and vice versa). 我想了解何时在Redux可观察的史诗上使用Redux中间件是合适的(反之亦然)。

From the redux middleware documentation 来自Redux中间件文档

It provides a third-party extension point between dispatching an action, and the moment it reaches the reducer. 它在调度动作与到达减速器之间提供了第三方扩展点。 People use Redux middleware for logging, crash reporting, talking to an asynchronous API, routing, and more. 人们使用Redux中间件进行日志记录,崩溃报告,与异步API对话,路由等等。

From the redux-observable documentation 从Redux可观察的文档

While you'll most commonly produce actions out in response to some action you received in, that's not actually a requirement! 尽管您通常会根据收到的某些动作做出动作,但这实际上不是必需的! Once you're inside your Epic, use any Observable patterns you desire as long as anything output from the final, returned stream, is an action. 一旦进入Epic,只要最终返回的流中的任何输出都是可操作的,就可以使用所需的任何Observable模式。

My understanding is that an action in a redux middleware may or may not hit a reducer and if it does, it may or may not result in a change of state. 我的理解是,redux中间件中的操作可能会或可能不会遇到减速器,如果这样做,则可能会或可能不会导致状态改变。 In an epic you can produce a new action which may or may not hit a reducer or result in a change of state. 在史诗中,您可以产生一个新动作,该动作可能会或可能不会撞击减速器或导致状态改变。

It looks like both can be used to enable side effects so the difference between the two is becoming a bit blurry to me. 看起来两者都可以用来产生副作用,所以两者之间的差异对我来说变得有点模糊。

Question: Is the FRP foundation the only thing that sets them apart or are there specific events in the lifecycle of an application that are better dealt with a classic middleware or an epic? 问题: FRP基础是唯一使它们区别开的东西吗?还是在应用程序的生命周期中存在特定事件,最好用经典的中间件或史诗来处理?

"Middleware" are a general type of thing that can be used to customize a Redux store. “中间件”是一种通用类型的事物,可用于自定义Redux存储。 redux-observable is a specific Redux middleware, which lets you use RxJS logic to interact with dispatched actions. redux-observable特定的 Redux中间件,它使您可以使用RxJS逻辑与调度的动作进行交互。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM