10BC0 fix: remove event listener for document and history (#76) · SuSunSam/lowcode-plugins@25a72d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 25a72d6

Browse files
authored
fix: remove event listener for document and history (alibaba#76)
1 parent 46f842d commit 25a72d6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/plugin-undo-redo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"dependencies": {
2121
"@alilc/lowcode-utils": "^1.0.0",
22-
"@alilc/lowcode-types": "^1.0.0",
22+
"@alilc/lowcode-types": "^1.1.9",
2323
"react": "^16.8.1",
2424
"react-dom": "^16.8.1"
2525
},

packages/plugin-undo-redo/src/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent } from 'react';
22
import { ILowCodePluginContext, project } from '@alilc/lowcode-engine';
33
import { Button, Icon } from '@alifd/next';
4-
import { PluginProps } from '@alilc/lowcode-types';
4+
import { PluginProps, IPublicTypeDisposable } from '@alilc/lowcode-types';
55

66
import './index.scss';
77

@@ -18,7 +18,8 @@ class UndoRedo extends PureComponent<IProps, IState> {
1818
static displayName = 'LowcodeUndoRedo';
1919

2020
private history: any;
21-
21+
private changeDocumentDispose?: IPublicTypeDisposable;
22+
private changeStateDispose?: IPublicTypeDisposable;
2223
constructor(props: any) {
2324
super(props);
2425
this.state = {
@@ -29,11 +30,11 @@ class UndoRedo extends PureComponent<IProps, IState> {
2930
}
3031

3132
init = (): void => {
32-
project.onChangeDocument(doc => {
33+
this.changeDocumentDispose = project.onChangeDocument(doc => {
3334
this.history = doc.history;
3435
this.updateState(this.history?.getState() || 0);
35-
36-
this.history.onChangeState(() => {
36+
this.changeStateDispose?.();
37+
this.changeStateDispose = this.history.onChangeState(() => {
3738
this.updateState(this.history?.getState() || 0);
3839
});
3940
});
@@ -54,6 +55,11 @@ class UndoRedo extends PureComponent<IProps, IState> {
5455
this.history.forward();
5556
};
5657

58+
componentWillUnmount() {
59+
this.changeDocumentDispose?.();
60+
this.changeStateDispose?.();
61+
}
62+
5763
render(): React.ReactNode {
5864
const { undoEnable, redoEnable } = this.state;
5965
return (

0 commit comments

Comments
 (0)
0