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:
- A JavaScript object that directly implements the members of the AsyncTree interface.
- A JavaScript function
- A JavaScript
Map
instance - A JavaScript
Set
instance - Any object that exposes an
unpack()
method which, when invoked, produces any of these listed treelike objects - A plain JavaScript object created with object literal syntax,
new Object()
, orObject.create(null)
. - A JavaScript
Array
instance - 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 */
}
}