11import { reaction , untracked , globalContext , IEventBus , createModuleEventBus } from '@alilc/lowcode-editor-core' ;
22import { IPublicTypeNodeSchema , IPublicModelHistory } from '@alilc/lowcode-types' ;
3+ import { Logger } from '@alilc/lowcode-utils' ;
4+
5+ const logger = new Logger ( { level : 'warn' , bizName : 'history' } ) ;
36
47export interface Serialization < K = IPublicTypeNodeSchema , T = string > {
58 serialize ( data : K ) : T ;
@@ -30,11 +33,15 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
3033 } ,
3134 } ;
3235
33- setSerialization ( serialization : Serialization < T , string > ) {
34- this . currentSerialization = serialization ;
36+ get hotData ( ) {
37+ return this . session . data ;
3538 }
3639
37- constructor ( dataFn : ( ) => T | null , private redoer : ( data : T ) => void , private timeGap : number = 1000 ) {
40+ constructor (
41+ dataFn : ( ) => T | null ,
42+ private redoer : ( data : T ) => void ,
43+ private timeGap : number = 1000 ,
44+ ) {
3845 this . session = new Session ( 0 , null , this . timeGap ) ;
3946 this . records = [ this . session ] ;
4047
@@ -68,8 +75,8 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
6875 } , { fireImmediately : true } ) ;
6976 }
7077
71- get hotData ( ) {
72- return this . session . data ;
78+ setSerialization ( serialization : Serialization < T , string > ) {
79+ this . currentSerialization = serialization ;
7380 }
7481
7582 isSavePoint ( ) : boolean {
@@ -84,16 +91,18 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
8491 this . asleep = false ;
8592 }
8693
87- go ( cursor : number ) {
94+ go ( originalCursor : number ) {
8895 this . session . end ( ) ;
8996
90- const currentCursor = this . session . cursor ;
97+ let cursor = originalCursor ;
9198 cursor = + cursor ;
9299 if ( cursor < 0 ) {
93100 cursor = 0 ;
94101 } else if ( cursor >= this . records . length ) {
95102 cursor = this . records . length - 1 ;
96103 }
104+
105+ const currentCursor = this . session . cursor ;
97106 if ( cursor === currentCursor ) {
98107 return ;
99108 }
@@ -106,7 +115,7 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
106115 this . redoer ( this . currentSerialization . unserialize ( hotData ) ) ;
107116 this . emitter . emit ( 'cursor' , hotData ) ;
108117 } catch ( e ) /* istanbul ignore next */ {
109- console . error ( e ) ;
118+ logger . error ( e ) ;
110119 }
111120
112121 this . wakeup ( ) ;
@@ -174,6 +183,7 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
174183 }
175184 return state ;
176185 }
186+
177187 /**
178188 * 监听 state 变更事件
179189 * @param func
@@ -209,6 +219,7 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
209219 this . emitter . removeAllListeners ( ) ;
210220 this . records = [ ] ;
211221 }
222+
212223 /**
213224 *
214225 * @deprecated
0 commit comments