Skip to content

Commit

Permalink
fix: refactor splice method to remove and purge nodes***
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Mar 6, 2024
1 parent 3dba0f4 commit 89beda6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions packages/designer/src/document/node/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,16 @@ export class NodeChildren implements Omit<IPublicModelNodeChildren<INode>,
*
*/
splice(start: number, deleteCount: number, node?: INode): INode[] {
let removedNode;
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;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/shell/src/model/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ export class NodeChildren implements IPublicModelNodeChildren {
* @param deleteCount
* @param node
*/
splice(start: number, deleteCount: number, node?: IPublicModelNode): any {
this[nodeChildrenSymbol].splice(start, deleteCount, (node as any)?.[nodeSymbol]);
splice(start: number, deleteCount: number, node?: IPublicModelNode): IPublicModelNode[] {
const removedNode = this[nodeChildrenSymbol].splice(start, deleteCount, (node as any)?.[nodeSymbol]);
return removedNode.map((item: InnerNode) => ShellNode.create(item)!);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/shell/model/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface IPublicModelNodeChildren<
* @param deleteCount
* @param node
*/
splice(start: number, deleteCount: number, node?: Node): any;
splice(start: number, deleteCount: number, node?: Node): Node[];

/**
* 返回指定下标的节点
Expand Down

0 comments on commit 89beda6

Please sign in to comment.