Skip to content

Commit

Permalink
Added convenience getters for retrieving root and node items and IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
gautelo committed Feb 2, 2024
1 parent dc426bc commit 6053ac5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/hierarchies/hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,31 @@ export class Hierarchy<Item, Id = Item> {
return [ ...this.#roots.values() ];
}

/** Get a shallow clone of the root items. */
public get rootItems() {
return this.roots.map(r => r.item);
}

/** Get a shallow clone of the root IDs. */
public get rootIds() {
return this.roots.map(r => this.#identify(r.item));
}

/** Get a shallow clone of all nodes. */
public get nodes() {
return [ ...this.#nodes.values() ];
}

/** Get a shallow clone of all node items. */
public get nodeItems() {
return this.roots.map(n => n.item);
}

/** Get a shallow clone of all node IDs. */
public get nodeIds() {
return this.roots.map(n => this.#identify(n.item));
}

/** Means of getting an ID for an `item`. */
public get identify() {
return this.#identify;
Expand Down

0 comments on commit 6053ac5

Please sign in to comment.