UNPKG

@daign/2d-pipeline

Version:
68 lines (67 loc) 1.92 kB
import { Observable } from '@daign/observable'; /** * Class that describes a node in a tree data structure. */ export declare abstract class GenericNode<T extends GenericNode<any>> extends Observable { /** * Reference to the parent node. */ parent: T | null; /** * References to the child nodes. */ children: T[]; /** * Name that is used by the parent as a unique identifier for the child. */ mappingName: string | null; /** * The child nodes referenced by their mapping name. */ private namedMapping; /** * Constructor. */ constructor(); /** * Append child node to this node. * Will throw an error when a name is passed that is not unique within the parent. * @param childNode The child node. * @param name The name of the child for the mapping. Optional. */ appendChild(childNode: T, name?: string): void; /** * Remove child node from this node. * Will do nothing if the given node is not one of the child nodes. * @param childNode The child node. */ removeChild(childNode: T): void; /** * Remove all child nodes from this node. */ clearChildren(): void; /** * Remove this node from its parent. * Will do nothing if node has no parent. */ removeFromParent(): void; /** * Get a child node by its name in the mapping. * Will throw an error if a child by this name does not exist. * @param name The name of the child. * @returns The child node. */ getChildByName(name: string): T; /** * Destroy this node and all its references. */ destroyNode(): void; /** * Destroy this node and all of its children. */ destroyRecursive(): void; /** * Call notifyObservers and propagate up the chain of ancestors. */ private propagateNotifyObservers; }