diff --git a/src/lib/data_structures/publication_tree.ts b/src/lib/data_structures/publication_tree.ts index 7f4c677..8c57729 100644 --- a/src/lib/data_structures/publication_tree.ts +++ b/src/lib/data_structures/publication_tree.ts @@ -52,6 +52,8 @@ export class PublicationTree implements AsyncIterable { */ #ndk: NDK; + #onNodeAddedCallbacks: Array<(address: string) => void> = []; + #onNodeResolvedCallbacks: Array<(address: string) => void> = []; constructor(rootEvent: NDKEvent, ndk: NDK) { @@ -187,6 +189,10 @@ export class PublicationTree implements AsyncIterable { this.#cursor.tryMoveTo(address); } + onNodeAdded(observer: (address: string) => void) { + this.#onNodeAddedCallbacks.push(observer); + } + /** * Registers an observer function that is invoked whenever a new node is resolved. Nodes are * added lazily. @@ -479,6 +485,8 @@ export class PublicationTree implements AsyncIterable { const lazyNode = new Lazy(() => this.#resolveNode(address, parentNode)); parentNode.children!.push(lazyNode); this.#nodes.set(address, lazyNode); + + this.#onNodeAddedCallbacks.forEach(observer => observer(address)); } /**