MCPcopy Index your code
hub / github.com/alibaba/lowcode-engine / constructor

Method constructor

packages/designer/src/document/history.ts:43–79  ·  view source on GitHub ↗
(
      dataFn: () => T | null,
      private redoer: (data: T) => void,
      private document?: IDocumentModel,
    )

Source from the content-addressed store, hash-verified

41 private timeGap: number = 1000;
42
43 constructor(
44 dataFn: () => T | null,
45 private redoer: (data: T) => void,
46 private document?: IDocumentModel,
47 ) {
48 this.session = new Session(0, null, this.timeGap);
49 this.records = [this.session];
50
51 reaction((): any => {
52 return dataFn();
53 }, (data: T) => {
54 if (this.asleep) return;
55 untracked(() => {
56 const log = this.currentSerialization.serialize(data);
57
58 // do not record unchanged data
59 if (this.session.data === log) {
60 return;
61 }
62
63 if (this.session.isActive()) {
64 this.session.log(log);
65 } else {
66 this.session.end();
67 const lastState = this.getState();
68 const cursor = this.session.cursor + 1;
69 const session = new Session(cursor, log, this.timeGap);
70 this.session = session;
71 this.records.splice(cursor, this.records.length - cursor, session);
72 const currentState = this.getState();
73 if (currentState !== lastState) {
74 this.emitter.emit('statechange', currentState);
75 }
76 }
77 });
78 }, { fireImmediately: true });
79 }
80
81 setSerialization(serialization: Serialization<T, string>) {
82 this.currentSerialization = serialization;

Callers

nothing calls this directly

Calls 7

getStateMethod · 0.95
serializeMethod · 0.65
logMethod · 0.65
spliceMethod · 0.65
emitMethod · 0.65
isActiveMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected