Skip to content

Commit

Permalink
feat(ts-model-api): add method for removing node
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik Schmitz authored and drik98 committed Jun 19, 2024
1 parent 5e8a62b commit 1501433
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ts-model-api/src/ChildrenAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SingleChildAccessor<ChildT extends ITypedNode> extends ChildrenAcce
public setNew(): ChildT {
const existing = this.get();
if (existing !== undefined) {
this.parentNode.removeChild(existing.unwrap())
existing.remove();
}
return this.wrapChild(this.parentNode.addNewChild(this.role, 0, undefined))
}
Expand Down
4 changes: 4 additions & 0 deletions ts-model-api/src/TypedNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export class TypedNode implements ITypedNode {
return this._node;
}

remove(): void {
this._node.getParent()?.removeChild(this._node);
}
}

export interface ITypedNode {
unwrap(): INodeJS
remove(): void
}

export class UnknownTypedNode extends TypedNode {
Expand Down

0 comments on commit 1501433

Please sign in to comment.