SemanticRegistry
class exported by @mwillbanks/tuil-ink.
class
Public class exported by @mwillbanks/tuil-ink.
export class SemanticRegistry {
readonly #nodes: Map<string, SemanticNode>;
readonly #observers: Set<() => void>;
readonly #layout?: LayoutProjection;
constructor(layout?: LayoutProjection) {
this.#nodes = new Map();
this.#observers = new Set();
this.#layout = layout;
}
register(node: SemanticNode): () => void {
this.#nodes.set(node.key, Object.freeze({ ...node }));
this.#project(node);
this.#notify();
return () => {
this.#nodes.delete(node.key);
this.#layout?.remove(node.id ?? node.key);
this.#notify();
};
}
update(node: SemanticNode): void {
this.#nodes.set(node.key, Object.freeze({ ...node }));
this.#project(node);
this.#notify();
}
nodes(): readonly SemanticNode[] {
return [...this.#nodes.values()];
}
observe(observer: () => void): () => void {
this.#observers.add(observer);
return deleteOnDispose(this.#observers, observer);
}
#notify(): void {
for (const observer of this.#observers) observer();
}
#project(node: SemanticNode): void {
if (!this.#layout || !node.layout) return;
this.#layout.upsert({
id: node.id ?? node.key,
...node.layout,
semantics: node,
});
}
}Members
| Member | Type | Required | Description | Related types |
|---|---|---|---|---|
#nodes | Map<string, SemanticNode> | Yes | The #nodes member uses the Map<string, SemanticNode> contract. | SemanticNode |
#observers | Set<() => void> | Yes | The #observers member uses the Set<() => void> contract. | — |
#layout | LayoutProjection | undefined | No | The #layout member uses the LayoutProjection | undefined contract. | — |
__constructor | any | Yes | The __constructor member uses the any contract. | — |
register | (node: SemanticNode) => () => void | Yes | The register member uses the (node: SemanticNode) => () => void contract. | SemanticNode |
update | (node: SemanticNode) => void | Yes | The update member uses the (node: SemanticNode) => void contract. | SemanticNode |
nodes | () => readonly SemanticNode[] | Yes | The nodes member uses the () => readonly SemanticNode[] contract. | SemanticNode |
observe | (observer: () => void) => () => void | Yes | The observe member uses the (observer: () => void) => () => void contract. | — |
#notify | () => void | Yes | The #notify member uses the () => void contract. | — |
#project | (node: SemanticNode) => void | Yes | The #project member uses the (node: SemanticNode) => void contract. | SemanticNode |
Parameters
This declaration has no public members.
Returns
This declaration does not return a value.
Throws
No thrown errors are documented for this declaration.
Related types
Source
View the secondary source reference