fix: refactor splice method to remove and purge nodes***

This commit is contained in:
liujuping 2024-03-06 16:50:20 +08:00 committed by JackLian
parent a423a7dab5
commit 4c83b945a7
3 changed files with 12 additions and 5 deletions

View File

@ -307,10 +307,16 @@ export class NodeChildren implements Omit<IPublicModelNodeChildren<INode>,
* *
*/ */
splice(start: number, deleteCount: number, node?: INode): INode[] { splice(start: number, deleteCount: number, node?: INode): INode[] {
let removedNode;
if (node) { if (node) {
return this.children.splice(start, deleteCount, node); removedNode = this.children.splice(start, deleteCount, node);
} else {
removedNode = this.children.splice(start, deleteCount);
} }
return this.children.splice(start, deleteCount);
removedNode.forEach(d => d?.purge());
return removedNode;
} }
/** /**

View File

@ -97,8 +97,9 @@ export class NodeChildren implements IPublicModelNodeChildren {
* @param deleteCount * @param deleteCount
* @param node * @param node
*/ */
splice(start: number, deleteCount: number, node?: IPublicModelNode): any { splice(start: number, deleteCount: number, node?: IPublicModelNode): IPublicModelNode[] {
this[nodeChildrenSymbol].splice(start, deleteCount, (node as any)?.[nodeSymbol]); const removedNode = this[nodeChildrenSymbol].splice(start, deleteCount, (node as any)?.[nodeSymbol]);
return removedNode.map((item: InnerNode) => ShellNode.create(item)!);
} }
/** /**

View File

@ -78,7 +78,7 @@ export interface IPublicModelNodeChildren<
* @param deleteCount * @param deleteCount
* @param node * @param node
*/ */
splice(start: number, deleteCount: number, node?: Node): any; splice(start: number, deleteCount: number, node?: Node): Node[];
/** /**
* *