Tree
Module Collections.Trees
Mutable
Section titled “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/collections/bundle"
const root = Trees.Mutable.rootWrapped(`root`);// Add 'a' as the child of the root nodelet a = root.addValue(`a`);// Add `aa` as the child of `a`let b = a.addValue(`aa`);b.hasParent(a); // True
From Object
Section titled “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/collections/bundle"
const myObj = { name: `Pedro`, size: 45, colour: `orange` };const root = Trees.FromObject.asDynamicTraversable(myObj);
for (const v of Trees.Traverse.breadthFirst(root)) { // v.getValue() yields: // { name: 'name', sourceValue: 'Pedro' ...}, // { name: 'size', sourceValue: 45 ... } // ...}
create in contrast will take a snapshot of the object, returning a Type TreeNode representation.
Importing
Section titled “Importing”// Sub moduleimport { Stacks } from "@ixfx/collections.js"// Eg: Stacks.immutable();
// Whole moduleimport * as Collections from "@ixfx/collections.js"// Eg: Collections.Stacks.immutable();
// From bundleimport { Collections } from "@ixfx"// Eg: Collections.Stacks.immutable();
// And within your HTML's <HEAD> </HEAD> block:<script type="importmap">{ "imports": { "@ixfx":"/ixfx/index.js", "@ixfx/": "/ixfx/" } }</script>
// Sub module from parentimport { Stacks } from "@ixfx/collections.js"// Eg: Stacks.immutable();
// Whole parent moduleimport * as Collections from "@ixfx/collections.js"// Eg: Collections.Stacks.immutable();
// From the bundleimport { Collections } from "@ixfx/bundle.js"// Eg: Collections.Stacks.immutable();
// Sub module from parentimport { Stacks } from "https://unpkg.com/@ixfx/collections/bundle"// Eg: Stacks.immutable();
// Whole parent moduleimport * as Collections from "https://unpkg.com/@ixfx/collections/bundle"// Eg: Collections.Stacks.immutable();
// Single module from the bundleimport { Collections } from "https://unpkg.com/@ixfx/bundle"// Eg: Collections.Stacks.immutable();