Returns a projection of node as a dynamic traversable. This means that the tree structure is dynamically created as last-minute as possible.
node
The type when calling getValue() is TraverseObjectEntryStatic:
getValue()
type EntryStatic = Readonly<{ name: string, value: any ancestors: string[] }> Copy
type EntryStatic = Readonly<{ name: string, value: any ancestors: string[] }>
Note that the object identity of TraversableTree return results is not stable. This is because they are created on-the-fly by reading fields of node.
const c1 = [ ...asDynamicTraversable(someObject).children() ];const c2 = [ ...asDynamicTraversable(someObject).children() ];// Object identity is not the samec1[ 0 ] === c1[ 0 ]; // false// ...even though its referring to the same valuec1[ 0 ].getValue() === c1[ 0 ].getValue(); // true Copy
const c1 = [ ...asDynamicTraversable(someObject).children() ];const c2 = [ ...asDynamicTraversable(someObject).children() ];// Object identity is not the samec1[ 0 ] === c1[ 0 ]; // false// ...even though its referring to the same valuec1[ 0 ].getValue() === c1[ 0 ].getValue(); // true
Instead .getIdentity() to get a stable identity:
c1[ 0 ].getIdentity() === c2[ 0 ].getIdentity(); // true Copy
c1[ 0 ].getIdentity() === c2[ 0 ].getIdentity(); // true
Object to read
Options when creating traversable
Do not use
Optional
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 ... }// ...} Copy
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 ... }// ...}
Returns a projection of
nodeas a dynamic traversable. This means that the tree structure is dynamically created as last-minute as possible.The type when calling
getValue()is TraverseObjectEntryStatic:Note that the object identity of TraversableTree return results is not stable. This is because they are created on-the-fly by reading fields of
node.Instead .getIdentity() to get a stable identity: