fix: 增加 onChangeDocument 的补偿机制

This commit is contained in:
lihao.ylh 2021-12-30 15:54:19 +08:00
parent eca95b288f
commit 7d7615cdce
7 changed files with 19 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import { EventEmitter } from 'events';
import { autorun, reaction, mobx, untracked, globalContext, Editor } from '@ali/lowcode-editor-core';
import { NodeSchema } from '@ali/lowcode-types';
import { History as ShellHistory } from '@ali/lowcode-shell';
// TODO: cache to localStorage
@ -100,7 +101,7 @@ export class History {
this.redoer(currentSerialization.unserialize(hotData));
this.emitter.emit('cursor', hotData);
} catch (e) {
//
console.error(e);
}
this.wakeup();
@ -194,6 +195,10 @@ export class History {
isModified() {
return this.isSavePoint();
}
internalToShellHistory() {
return new ShellHistory(this);
}
}
class Session {

View File

@ -1,5 +1,6 @@
export {
Title,
Tip,
shallowIntl,
createIntl,
createSetterContent,

View File

@ -42,7 +42,7 @@ export default class DocumentModel {
this[editorSymbol] = document.designer.editor as Editor;
this.selection = new Selection(document);
this.detecting = new Detecting(document);
this.history = new History(document);
this.history = new History(document.getHistory());
this.canvas = new Canvas(document.designer);
}

View File

@ -26,6 +26,10 @@ export default class Event {
}
on(event: string, listener: (...args: unknown[]) => void) {
if (event.startsWith('designer')) {
logger.warn('designer events are disabled');
return;
}
this[editorSymbol].on(event, listener);
}

View File

@ -1,13 +1,11 @@
import { History as InnerHistory, DocumentModel as InnerDocumentModel } from '@ali/lowcode-designer';
import { documentSymbol, historySymbol } from './symbols';
import { historySymbol } from './symbols';
export default class History {
private readonly [documentSymbol]: InnerDocumentModel;
private readonly [historySymbol]: InnerHistory;
constructor(document: InnerDocumentModel) {
this[documentSymbol] = document;
this[historySymbol] = this[documentSymbol].getHistory();
constructor(history: InnerHistory) {
this[historySymbol] = history;
}
go(cursor: number) {

View File

@ -117,7 +117,10 @@ export default class Project {
* project document
*/
onChangeDocument(fn: (doc: DocumentModel) => void) {
// TODO: 思考一下是否要实现补偿触发能力
if (this[projectSymbol].currentDocument) {
fn(DocumentModel.create(this[projectSymbol].currentDocument)!);
return () => {};
}
return this[projectSymbol].onCurrentDocumentChange((originalDoc) => {
fn(DocumentModel.create(originalDoc)!);
});

View File

@ -1,4 +0,0 @@
module.exports = {
eslintType: 'typescript/react',
enableStylelint: false,
};