Skip to main content
Version: 1.2.0-beta1

Function: insertChildIfMissing()

Call Signature

insertChildIfMissing<T>(root, parentId, child): T

Defined in: src/Mnemonic/structural-migrations.ts:106

Inserts a child under the target parent when none of that parent's existing direct children share the same id. Returns the original tree when the parent is missing or the child is already present as a direct child.

Type Parameters

Type ParameterDescription
T extends StructuralNode<T>Tree node type (must extend { id: string; children?: readonly T[] } when helpers is omitted)

Parameters

ParameterTypeDescription
rootTRoot node to update
parentIdstringParent node that should receive the child
childTChild node to append

Returns

T

Updated tree with the child inserted once

Call Signature

insertChildIfMissing<T>(root, parentId, child, helpers): T

Defined in: src/Mnemonic/structural-migrations.ts:119

Inserts a child under the target parent when no existing child shares the same id. Returns the original tree when the parent is missing or the child is already present.

Type Parameters

Type ParameterDescription
TTree node type

Parameters

ParameterTypeDescription
rootTRoot node to update
parentIdstringParent node that should receive the child
childTChild node to append
helpersStructuralTreeHelpers<T>Adapter for custom node shapes

Returns

T

Updated tree with the child inserted once