From c9fbe8f98393a681d9c093341e12288f0f0f8cf3 Mon Sep 17 00:00:00 2001 From: Hendrik Schmitz Date: Mon, 10 Jun 2024 09:03:58 +0200 Subject: [PATCH] feat(ts-model-api): add method for removing node --- .../src/jsMain/kotlin/org/modelix/model/api/NodeAdapterJS.kt | 4 ++++ ts-model-api/src/ChildrenAccessor.ts | 2 +- ts-model-api/src/INodeJS.ts | 2 ++ ts-model-api/src/TypedNode.ts | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/model-api/src/jsMain/kotlin/org/modelix/model/api/NodeAdapterJS.kt b/model-api/src/jsMain/kotlin/org/modelix/model/api/NodeAdapterJS.kt index b91f99ca34..6f29e912b9 100644 --- a/model-api/src/jsMain/kotlin/org/modelix/model/api/NodeAdapterJS.kt +++ b/model-api/src/jsMain/kotlin/org/modelix/model/api/NodeAdapterJS.kt @@ -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 { return node.getReferenceRoles().toTypedArray() } diff --git a/ts-model-api/src/ChildrenAccessor.ts b/ts-model-api/src/ChildrenAccessor.ts index 57f70f61cd..a01727411c 100644 --- a/ts-model-api/src/ChildrenAccessor.ts +++ b/ts-model-api/src/ChildrenAccessor.ts @@ -47,7 +47,7 @@ export class SingleChildAccessor 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)) } diff --git a/ts-model-api/src/INodeJS.ts b/ts-model-api/src/INodeJS.ts index 5bc51e02e2..f040c14259 100644 --- a/ts-model-api/src/INodeJS.ts +++ b/ts-model-api/src/INodeJS.ts @@ -8,6 +8,8 @@ export interface INodeJS { getRoleInParent(): string | undefined getParent(): INodeJS | undefined + remove(): void + getChildren(role: string | undefined): Array getAllChildren(): Array moveChild(role: string | undefined, index: number, child: INodeJS): void diff --git a/ts-model-api/src/TypedNode.ts b/ts-model-api/src/TypedNode.ts index f8dd4e5ece..0dd3e89bab 100644 --- a/ts-model-api/src/TypedNode.ts +++ b/ts-model-api/src/TypedNode.ts @@ -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 {