Treelike objects

Many features in the async-tree library and the Origami expression language built-in functions accept async trees in a variety of treelike objects.

The treelike types are, in order of priority:

  1. A JavaScript object that directly implements the members of the AsyncTree interface.
  2. A JavaScript function
  3. A JavaScript Map instance
  4. A JavaScript Set instance
  5. Any object that exposes an unpack() method which, when invoked, produces any of these listed treelike objects
  6. A plain JavaScript object created with object literal syntax, new Object(), or Object.create(null).
  7. A JavaScript Array instance
  8. Any other kind of JavaScript object

The easiest way for you to write a function that can accept any treelike object as a parameter is to pass that parameter to Tree.from(). The from() function considers the types above in priority order and, if the type applies, wraps the object with a library class such as ObjectTree and returns the resulting tree.

async function manipulateTree(treelike) {
  const tree = Tree.from(treelike);
  if (tree) {
    /* `tree` is an async tree */
  }
}