[英]How to revert side-effects when disabling an action in Redux logger?
Assume that an action creator (or a middleware) has a side-effect of starting a service: service.start()
. 假设动作创建者(或中间件)具有启动服务的副作用: service.start()
。
The disable-action feature of redux-devtools reverts the state changes due to that specific action. redux-devtools的disable-action功能可恢复由于该特定操作而导致的状态更改。 How do we make sure that the side-effects are also reverted, which in the above example means calling service.stop()
? 我们如何确保副作用也得到恢复,在上面的示例中这意味着调用service.stop()
? I guess what is needed is an observer for the state, but I'm not sure if this is the flux/redux way of implementing it. 我猜需要的是状态的观察者,但是我不确定这是否是实现状态的通量/冗余方式。
You can't do this. 你做不到 There are no means of reverting side effects in Redux (eg how do you “undo” a GET request?). 在Redux中无法恢复副作用(例如,如何“撤消” GET请求?)。
Ultimately side effects shouldn't affects the application unless they ultimately produce actions. 最终,除非副作用最终产生作用,否则它们不应影响应用程序。 (For example, a GET request ultimately produces an action with the response.) And when there are actions, they can be reverted. (例如,一个GET请求最终会产生一个带有响应的动作。)并且当有动作时,它们可以被还原。
So you can't revert side effects, but this shouldn't matter anyway. 因此,您无法恢复副作用,但这无论如何都没关系。 You can revert actions that are dispatched as the result, and nothing but actions can change application's state. 您可以还原作为结果调度的操作,除了操作之外,其他任何操作都不能更改应用程序的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.