NodeIndex
Find nodes by name or tag.
ts
import { NodeIndex } from "willow";NodeIndex
ts
class NodeIndexOpt-in registry for looking up nodes by name or tag. Supports SQL LIKE-style % wildcards, multi-tag intersection queries, and automatic cleanup when a node is disposed.
NodeIndex: constructors
ts
new NodeIndex()NodeIndex: methods
| Member | Description |
|---|---|
add(node: Node, ...tags: Array<string>): void | Registers a node in the index, optionally with initial tags. |
remove(node: Node, ...tags: Array<string>): void | Removes tags from a node; if no tags are provided, unregisters the node entirely. |
tag(node: Node, tag: string): void | Adds a single tag to a node. |
untag(node: Node, tag: string): void | Removes a single tag from a node. Safe to call if the node does not have this tag. |
findByName(pattern: string): Node | null | Returns the first registered node matching the name pattern (supports % wildcards), or null if not found. |
findAllByName(pattern: string): Array<Node> | Returns all registered nodes matching the name pattern (supports % wildcards). |
findByTag(pattern: string): Array<Node> | Returns all nodes matching the given tag pattern (supports % wildcards). |
findByTags(...tags: Array<string>): Array<Node> | Returns all nodes that have every one of the given tags (AND query). |
countByTag(tag: string): int | Returns the number of nodes with the given tag without allocating an array. |
each(fn: Function): void | Iterates all registered nodes. Callback can return false to stop early. |
eachByTag(tag: string, fn: Function): void | Iterates all nodes with the given tag. Callback can return false to stop early. |
clear(): void | Removes all nodes and tags from the index. |
clearNode(node: Node): void | Removes all entries (name and tags) for a specific node. |