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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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