diff --git a/src/lib/data_structures/publication_tree.ts b/src/lib/data_structures/publication_tree.ts index a9076ea..c6e7802 100644 --- a/src/lib/data_structures/publication_tree.ts +++ b/src/lib/data_structures/publication_tree.ts @@ -7,11 +7,30 @@ interface PublicationTreeNode { children?: PublicationTreeNode[]; } -// TODO: Add an iterator over the leaves of the tree. -export class PublicationTree { +export class PublicationTree implements Iterable { + /** + * The root node of the tree. + */ private root: PublicationTreeNode; + + /** + * A map of addresses in the tree to their corresponding nodes. + */ private nodes: Map; + + /** + * A map of addresses in the tree to their corresponding events. + */ private events: Map; + + /** + * The address of the last-visited node. Used for iteration and progressive retrieval. + */ + private bookmark?: string; + + /** + * The NDK instance used to fetch events. + */ private ndk: NDK; constructor(rootEvent: NDKEvent, ndk: NDK) { @@ -70,6 +89,16 @@ export class PublicationTree { return event; } + [Symbol.iterator](): Iterator { + return this; + } + + next(): IteratorResult { + // TODO: Implement iteration from the bookmark over subsequent leaves. + + return { done: true, value: null }; + } + // #region Private Methods /**