Many features in the async-tree library and the Origami expression language built-in functions accept map-like arguments.
A map-like object is any of the following:
- A JavaScript
Mapobject - An
AsyncMapobject (an asynchronous variant ofMap) - An object with the same interface as
MaporAsyncMap: it may be of a different class, but nevertheless has the same methods and properties - A JavaScript
Arrayinstance - A JavaScript function
- A JavaScript
Iteratorinstance - A JavaScript
Setinstance - A plain JavaScript object created with object literal syntax,
new Object(), orObject.create(null).
The easiest way for you to write a function that can accept any map-like object as a parameter is to pass that parameter to Tree.from(). The from() function considers the types above and, if the input matches one of the above types, returns a Map or AsyncMap object. If necessary, from() will wrap the input with a map class like ObjectMap.
async function manipulateTree(maplike) {
const map = Tree.from(maplike);
if (map) {
/* `map` is a sync or async map */
}
}
Note: the Tree.from method accepts any JavaScript object, but the helper function Tree.isMaplike returns false for an object that isn’t one of the types listed above.