How to use performant-array-to-tree - 5 common examples

To help you get started, we’ve selected a few performant-array-to-tree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marmelab / react-admin / packages / ra-tree-core / src / getTreeFromArray.js View on Github external
export default (data, parentSource) => {
    // arrayToTree requires top level nodes to have their parent id set to null
    const sanitizedData = data.map(item => ({
        ...item,
        [parentSource]: item[parentSource] || null,
    }));

    return arrayToTree(sanitizedData, {
        id: 'id',
        parentId: parentSource,
    })
        .map(node => createNode(node))
        .map(node => addParent(node, null));
};
github maximebj / agb.plugin / src / blocks / summary / list.js View on Github external
render() {

    const { ordered, blocks, setAttributes } = this.props

    // Get headings list + define some needed datas
    const headingsRaw = this.computeOutlineHeadings( blocks )

    // Get parents Id in order to make a tree for nested ul/ol > li
    const headingsFlat = this.compute( headingsRaw )

    // Make the tree
    const headings = arrayToTree( headingsFlat, { id: 'clientId', parentId: 'parentId' } )

    return (
      ordered && (
        <ol>
          
        </ol>
      ) || (
        <ul>
          
        </ul>
      )
    )
  }
}
github communicode / communikey-frontend / src / components / data / views / CategoryTree.js View on Github external
  generateTreeFromFlatData = categories => arrayToTree(categories, {id: "id", parentId: "parent"});
github communicode / communikey-frontend / src / components / data / CategoryModal.js View on Github external
  generateTreeFromFlatData = categories => arrayToTree(categories, {id: "id", parentId: "parent"});
github communicode / communikey-frontend / src / components / data / KeyModal.js View on Github external
  generateTreeFromFlatData = categories => arrayToTree(categories, {id: "id", parentId: "parent"});

performant-array-to-tree

Converts an array of items with ids and parent ids to a nested tree in a performant `O(n)` way. Runs in browsers and node.

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis

Popular performant-array-to-tree functions