简体   繁体   English

在Redux记录器中禁用操作时如何恢复副作用?

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

相关问题 React-Redux:使用redux-undo改变状态以模拟动作的副作用 - React-Redux: Mutating the state to emulate action side-effects with redux-undo 使用“useReducer”时如何添加副作用? - How to add side-effects when using "useReducer"? redux-saga:如何以编程方式为收益创建多个调用/副作用? - redux-saga: How to create multiple calls/side-effects programmatically for yield? redux减速器的副作用,减速器返回值的形式不同于初始状态 - redux reducer side-effects, reducer return value has a form that is different from the initial state 我应该在哪里添加代码来运行附加到 Redux state 的副作用? - Where should I add code to run side-effects attached to Redux state? 使用 redux 工具包时,定义动作副作用(不是异步 thunk)的正确方法是什么? - What is a proper way of defining side effects in action(not async thunks) when using redux toolkit? 如何处理react / redux中的副作用? - How to handle side effects in react/redux? Redux 减速器的副作用 - Side effects in Redux reducer 在 React 中克隆整个 state object 会导致副作用吗? - Will cloning the whole state object in React lead to side-effects? 在React组件之间注入或共享具有副作用的功能 - Inject or share functionalities with side-effects between React components
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM