Skip to content

Tree

Module Collections.Trees

Mutable

The Trees.Mutable sub-module is a collection of functions for working with trees.

For more object-oriented access, use rootWrapped , which gives a WrappedNode instance.

import { Trees } from "https://unpkg.com/ixfx/dist/collections.js"
const root = Trees.Mutable.rootWrapped(`root`);
// Add 'a' as the child of the root node
let a = root.addValue(`a`);
// Add `aa` as the child of `a`
let b = a.addValue(`aa`);
b.hasParent(a); // True

From Object

The FromObject sub-module allows tree-like access to objects via asDynamicTraversable and create .

asDynamicTraversable will present a dynamic tree structure based on the live object.

It returns a TraversableTree which can be used with functions in the Trees.Traverse sub-module.

import { Trees } from "https://unpkg.com/ixfx/dist/collections.js"
const root = Trees.FromObject.asDynamicTraversable(myObj);
for (const v of Trees.Traverse.breadthFirst(root)) {
// Iterate breadth-first over `myObj`
}

create in contrast will take a snapshot of the object, returning a Type TreeNode representation.