Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Async tree traversal for nodejs
CoffeeScript
tag: v0.0.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
specs
src
.gitignore
.npmignore
README.md
package.json

README.md

Async tree traversal for nodejs

tree-monkey takes a JSON or object literal tree of the form

{
  "nodeA": {
    "nodeAA": {
      "nodeAAA": 'leaf'
    }
  },
  "nodeB": {
    "nodeBA": 42
    "nodeBB": []
  }
}

and traversers it asynchronously.

Usage

The basic usage is as follows:

var monkey = require('tree-monkey')
  , tree = { ... };

monkey.preOrder(tree, function (node, path, callback) {
  // do something async with the current node and/or path
  ...

  // signal that you are done
  callback();
});

Pre-order traversal

Visits all nodes depth-first in async pre-order, meaning each parent node is visited before its child nodes and then all child nodes are visited asynchronously. This means all branches are visited in their own speed, so to say, and we can't know the order in which they will complete.

preOrder(tree, nodeFunction, callback)

Arguments:

tree
the tree to traverse
nodeFunction
the function called on each node. Receives the current node, the current path and a callback as arguments. Callback *must* be called eventually.
callback
an optional callback, which is called after the whole tree has been traversed

Post-order traversal

Visits all nodes depth-first in async prost-order, meaning children will be visited before their parent node. Child nodes are visited asynchronously, meaning we can't know the order in which they will complete.

preOrder(tree, nodeFunction, callback)

Take the same arguments as preOrder

Something went wrong with that request. Please try again.