mirror of
https://github.com/MrXujiang/h5-Dooring.git
synced 2025-12-15 04:12:49 +00:00
39 lines
1.2 KiB
Markdown
39 lines
1.2 KiB
Markdown
<!--
|
||
* @Date: 2021-01-17 14:27:28
|
||
* @LastEditors: chentianshang
|
||
* @LastEditTime: 2021-01-17 21:50:17
|
||
* @FilePath: /github-h5-Dooring/doc/zh/guide/functionRealization/revocation.md
|
||
-->
|
||
|
||
# 撤销/重做
|
||
|
||
撤销重做我们主要使用了 redux-undo 这个库,配合 Dva 使用,具体使用方法参考如下操作:
|
||
|
||
```js
|
||
import { createLogger } from "redux-logger";
|
||
import { message } from "antd";
|
||
import undoable, { StateWithHistory } from "redux-undo";
|
||
import { Reducer, AnyAction } from "redux";
|
||
|
||
export const dva = {
|
||
config: {
|
||
onAction: createLogger(),
|
||
onError(e: Error) {
|
||
message.error(e.message, 3);
|
||
},
|
||
onReducer: (reducer: Reducer<any, AnyAction>) => {
|
||
let undoReducer = undoable(reducer);
|
||
return function(state: StateWithHistory<any>, action: AnyAction) {
|
||
let newState = undoReducer(state, action);
|
||
let router = newState.present.router
|
||
? newState.present.router
|
||
: newState.present.routing;
|
||
return { ...newState, router: router };
|
||
};
|
||
}
|
||
}
|
||
};
|
||
```
|
||
|
||
以上我们就实现了全局配置 redux-undo,在撤销重做按钮中我们就可以触发对应的方法来实现撤销重做的功能,其次我们还使用了 redux-logger 来实现 redux 的日志输出。
|