[英]Implementing Undo with redux-saga
If an action removeItem(itemId)
is fired from the UI it should first delete the corresponding item from the state and then call the associated saga. 如果从UI触发了动作
removeItem(itemId)
则它应首先从状态中删除相应的项,然后调用关联的传奇。 If the saga fails it should reset the state to it's original state. 如果传奇失败,则应将状态重置为其原始状态。
I was wondering if you can append information to the action payload within the reducers then fire a failed
action from the saga with the same payload. 我想知道是否可以将信息附加到化简器中的动作有效载荷上,然后使用相同的有效载荷从传奇中触发
failed
动作。 This is assuming that the reducer will always be fired first (Is it true?) 这是假设减速器将始终先被点火(是真的吗?)
You shouldn't dispatch from inside your reducer. 您不应该从减速器内部调度。 A reducers job is to take current state, an action, and return new state from the reduction of the two.
还原器的工作是采取当前状态,一个动作,并从两者的还原中返回新状态。 That's it.
而已。 What you're trying to do can be accomplished by a strategy like the following:
您尝试执行的操作可以通过以下策略来完成:
itemId
to get a reference to the item and store it locally. itemId
获取对该项目的引用并将其存储在本地。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.