Skip to content

NodeIndex ​

Find nodes by name or tag.

ts
import { NodeIndex } from "willow";

NodeIndex ​

ts
class NodeIndex

Opt-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 ​

MemberDescription
add(node: Node, ...tags: Array<string>): voidRegisters a node in the index, optionally with initial tags.
remove(node: Node, ...tags: Array<string>): voidRemoves tags from a node; if no tags are provided, unregisters the node entirely.
tag(node: Node, tag: string): voidAdds a single tag to a node.
untag(node: Node, tag: string): voidRemoves a single tag from a node. Safe to call if the node does not have this tag.
findByName(pattern: string): Node | nullReturns 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): intReturns the number of nodes with the given tag without allocating an array.
each(fn: Function): voidIterates all registered nodes. Callback can return false to stop early.
eachByTag(tag: string, fn: Function): voidIterates all nodes with the given tag. Callback can return false to stop early.
clear(): voidRemoves all nodes and tags from the index.
clearNode(node: Node): voidRemoves all entries (name and tags) for a specific node.