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 c9fbe8f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class NodeAdapterJS(val node: INode) : INodeJS_ {
node.removeChild((child as NodeAdapterJS).node)
}

override fun remove() {
node.parent?.removeChild(node)
}

override fun getReferenceRoles(): Array<String> {
return node.getReferenceRoles().toTypedArray()
}
Expand Down
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
2 changes: 2 additions & 0 deletions ts-model-api/src/INodeJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface INodeJS {
getRoleInParent(): string | undefined
getParent(): INodeJS | undefined

remove(): void

getChildren(role: string | undefined): Array<INodeJS>
getAllChildren(): Array<INodeJS>
moveChild(role: string | undefined, index: number, child: INodeJS): void
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.remove();
}
}

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

export class UnknownTypedNode extends TypedNode {
Expand Down

0 comments on commit c9fbe8f

Please sign in to comment.