@esfx/async-iter-hierarchy
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@esfx/async-iter-hierarchy

A Symbol-based API for defining an ECMAScript AsyncIterable with an inherent hierarchy.

Overview

Installation

npm i @esfx/async-iter-hierarchy

Usage

import { AsyncHierarchyIterable, Hierarchical, HierarchyProvider } from "@esfx/async-iter-hierarchy";

interface Node {
    parent?: Node;
    children?: Node[];
    ...
}

const hierarchyProvider: HierarchyProvider<Node> = {
    parent(node: Node) { return node.parent; },
    children(node: Node) { return node.children; },
};

class MyAsyncHierarchyIterable implements AsyncHierarchyIterable<Node> {
    private #nodes: AsyncIterable<Node>;
    constructor(nodes: AsyncIterable<Node>) {
        this.#nodes = nodes;
    }

    [Symbol.asyncIterator]() {
        return this.#nodes[Symbol.asyncIterator]();
    }

    [Hierarchical.hierarchy]() {
        return hierarhcyProvider;
    }
}

API

You can read more about the API here.

Readme

Keywords

none

Package Sidebar

Install

npm i @esfx/async-iter-hierarchy

Weekly Downloads

6

Version

1.0.2

License

Apache-2.0

Unpacked Size

48.5 kB

Total Files

18

Last publish

Collaborators

  • rbuckton