Have ideas to improve npm?Join in the discussion! »

    @actualwave/walker-children-adapter

    0.1.5 • Public • Published

    Object Adapter for TreeWalker

    Adapter for Object tree that uses children property for child nodes. Each node of source structure must have name:String and children:Node[] properties.

    interface Node {
      name: string;
      children: Node[];
    }

    Source example:

    const sourceTree = {
      name: 'root',
      children: [
        { name: 'branch', children: [] },
        {
          name: 'branch',
          children: [
            { name: 'leaf', children: [] },
          ],
        },
        { name: 'branch', children: [] },
      ]
    };

    How to use

    Library exports adapter factory function createAdapter() that accepts two optional arguments:

    • getNodeName:Function -- Getter function to retrieve node name, default getter returns node.name property.
    • getNodeChildren:Function -- Getter function to retrieve list of node children, default getter returns node.children property. You can pass your own getters:
    import { create, setDefaultAdapter } from '@actualwave/tree-walker';
    import createAdapter from '@actualwave/walker-children-adapter';
     
    const adapter = createAdapter(
      (node) => node.label, // name getter
      (node) => node.list, // children getter
    );
     
    setDefaultAdapter(adapter);

    This adapter is created to be used with Tree Walker library, check its documentation on how to specify adapter. This adapter was used in Tree Walker Demo.

    Install

    npm i @actualwave/walker-children-adapter

    DownloadsWeekly Downloads

    11

    Version

    0.1.5

    License

    MIT

    Unpacked Size

    14.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar