tree-controller / Exports / TreeController / Tree
TreeController.Tree
Tree
holds a tree by its root and provides a flat array of
nodes built when its contructor is called. To do so, it assumes that
the provided nodes have a children
property that is an array of its
children.
If you're dealing with nodes shaped differently, the second paramenter can be provided to override default methods.
Name | Type |
---|---|
N |
any |
- children
- node
- nodes
- parent
- root
- _defaultGeParentFactory
- _defaultGetChildrenFactory
- _defaultGetNodeFactory
• new Tree<N
>(root
, options?
)
Name | Type |
---|---|
N |
any |
Name | Type |
---|---|
root |
N |
options? |
Partial <MethodsFactories <N > & ConstructorFunctions <N >> |
• Readonly
children: (node
: N
) => N
[]
▸ (node
): N
[]
Method
children
receives a node and returns its children
Name | Type |
---|---|
node |
N |
N
[]
• Readonly
node: (node
: N
) => N
▸ (node
): N
Method
node
simply receives a node and return that node
Name | Type |
---|---|
node |
N |
N
• Readonly
nodes: N
[]
Field
nodes
is a flat array containing every tree's nodes:
the root, each one of its childrens, and their children's
and so on.
• Readonly
parent: (node
: N
) => undefined
| null
| N
▸ (node
): undefined
| null
| N
Method
parent
receives a node and returns its parent
Name | Type |
---|---|
node |
N |
undefined
| null
| N
• Readonly
root: N
Field
root
is the provided tree root
▪ Static
Private
Readonly
_defaultGeParentFactory: (instance
: Tree
<any
>, ...args
: any
[]) => (node
: any
) => any
▸ (instance
, ...args
): (node
: any
) => any
Method
parent
is a factory function that will be called in
the Store constructor passing the Store instance as the
first parameter. It will override that instance's default method
for retrieving a node's parent
Name | Type | Description |
---|---|---|
instance |
Tree <any > |
of Storage |
...args |
any [] |
extra arguments you can provide as necessary |
fn
▸ (node
): any
Method
parent
receives a node and returns its parent
Name | Type |
---|---|
node |
any |
any
▪ Static
Private
Readonly
_defaultGetChildrenFactory: (instance
: Tree
<any
>, ...args
: any
[]) => (node
: any
) => any
[]
▸ (instance
, ...args
): (node
: any
) => any
[]
Method
children
is a factory function that will be called in
the Store constructor passing the Store instance as the
first parameter. It will override that instance's default method
for retrieving a node's children
Name | Type | Description |
---|---|---|
instance |
Tree <any > |
of Storage |
...args |
any [] |
extra arguments you can provide as necessary |
fn
▸ (node
): any
[]
Method
children
receives a node and returns its children
Name | Type |
---|---|
node |
any |
any
[]
▪ Static
Private
Readonly
_defaultGetNodeFactory: (instance
: Tree
<any
>, ...args
: any
[]) => (node
: any
) => any
▸ (instance
, ...args
): (node
: any
) => any
Method
node
is a factory function that will be called in
the Store constructor passing the Store instance as the
first parameter. It will override that instance's default method
for retrieving a node
Name | Type | Description |
---|---|---|
instance |
Tree <any > |
of Storage |
...args |
any [] |
extra arguments you can provide as necessary |
fn
▸ (node
): any
Method
node
simply receives a node and return that node
Name | Type |
---|---|
node |
any |
any
▸ Static
Private
Readonly
_defaultFillNodesArray<N
>(instance
): N
[]
Name | Type |
---|---|
N |
any |
Name | Type |
---|---|
instance |
Tree <N > |
N
[]