fix: 修复在切换页面时,没有销毁相应节点导致的一系列bug

This commit is contained in:
力皓 2020-08-24 20:37:51 +08:00
parent fe0fa8ea0b
commit 59fac25553
3 changed files with 18 additions and 11 deletions

View File

@ -33,7 +33,7 @@ export class DocumentModel {
/** /**
* Page/Component/Block * Page/Component/Block
*/ */
readonly rootNode: RootNode; rootNode: RootNode | null;
/** /**
* *
*/ */
@ -461,12 +461,16 @@ export class DocumentModel {
* *
*/ */
remove() { remove() {
this.purge();
this.project.removeDocument(this); this.project.removeDocument(this);
// todo: ... this.designer.postEvent('document.remove', { id: this.id });
} }
purge() { purge() {
// todo: this.rootNode?.purge();
this.nodes.clear();
this._nodesMap.clear();
this.rootNode = null;
} }
checkNesting(dropTarget: ParentalNode, dragObject: DragNodeObject | DragNodeDataObject): boolean { checkNesting(dropTarget: ParentalNode, dragObject: DragNodeObject | DragNodeDataObject): boolean {

View File

@ -699,11 +699,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
if (this.purged) { if (this.purged) {
return; return;
} }
if (this._parent) { // if (this._parent) {
// should remove thisNode before purge // // should remove thisNode before purge
this.remove(useMutator); // this.remove(useMutator);
return; // return;
} // }
this.purged = true; this.purged = true;
if (this.isParental()) { if (this.isParental()) {
this.children.purge(useMutator); this.children.purge(useMutator);
@ -711,8 +711,8 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
this.autoruns?.forEach((dispose) => dispose()); this.autoruns?.forEach((dispose) => dispose());
this.props.purge(); this.props.purge();
this.document.internalRemoveAndPurgeNode(this); this.document.internalRemoveAndPurgeNode(this);
this.document.destroyNode(this); this.document.destroyNode(this);
this.remove(useMutator);
} }
/** /**

View File

@ -54,6 +54,9 @@ export class TreeMaster {
time: (endTime - startTime).toFixed(2), time: (endTime - startTime).toFixed(2),
}); });
}); });
designer.editor.on('designer.document.remove', ({ id }) => {
this.treeMap.delete(id);
});
} }
private toVision() { private toVision() {