How to use tree-crawl - 4 common examples

To help you get started, we’ve selected a few tree-crawl 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 Seitenbau / SBideo / src / components / metaEditable / index.js View on Github external
getListOfArrayKey(tree, key) {
    let result = [];

    crawl(
      tree,
      node => {
        if (node.meta && node.meta[key]) {
          // check if it's a comma separated string instead of an array, and split it up
          const arr =
            node.meta[key][0] && node.meta[key][0].indexOf(',') > -1
              ? node.meta[key][0].split(',')
              : node.meta[key];

          result = this.mergeArray([result, arr]);
        }
      },
      { getChildren: node => node.items }
    );

    return this.uniqueArray(result);
github Seitenbau / SBideo / src / routes / home / index.js View on Github external
getVideoById(tree, videoId) {
    let result;
    crawl(
      tree,
      (node, context) => {
        if (node.type === 'video' && node.meta && node.meta.id === videoId) {
          result = node;

          // generate path to show breadcrumb and add to node
          node.path = context.cursor.stack.xs.reduce((result, item) => {
            if (item.node && item.node.meta) {
              result.push(item.node.meta.title);
            }
            return result;
          }, []);

          context.break();
        }
      },
github Seitenbau / SBideo / src / components / metaEditable / actions.js View on Github external
const setNewMetaInTree = (tree, newMeta) => {
  crawl(
    tree,
    (node, context) => {
      if (node.meta && node.meta.id === newMeta.id) {
        const newNode = node;
        newNode.meta = newMeta;

        context.parent.items[context.index] = newNode;
        context.replace(newNode);
      }
    },
    { getChildren: node => node.items }
  );
  return tree;
};
github Seitenbau / SBideo / src / routes / home / reducer.js View on Github external
const setNewMetaInTree = (tree, newMeta) => {
  crawl(
    tree,
    (node, context) => {
      if (node.meta && node.meta.id === newMeta.id) {
        const newNode = node;
        newNode.meta = newMeta;

        context.parent.items[context.index] = newNode;
        context.replace(newNode);
      }
    },
    { getChildren: node => node.items }
  );
  return tree;
};

tree-crawl

Agnostic tree traversal library.

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis

Popular tree-crawl functions