11import React , { PureComponent } from 'react' ;
22import { ILowCodePluginContext , project } from '@alilc/lowcode-engine' ;
33import { Button , Icon } from '@alifd/next' ;
4- import { PluginProps } from '@alilc/lowcode-types' ;
4+ import { PluginProps , IPublicTypeDisposable } from '@alilc/lowcode-types' ;
55
66import './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 (
38EB
span>
0 commit comments