Methods
(inner) asList(input) → {List}
Accepts an Array
, List
or null
and returns an equivalent List
. Passing in null
will return an empty List
.
Example
asList(null); // returns List()
asList([0,1,2]); // returns List().of(0,1,2)
asList(List().of(0,1,2)); // returns List().of(0,1,2)
Parameters:
Name | Type | Description |
---|---|---|
input |
Array | List | null | The input to be convert to a |
Returns:
The equivalent List
.
- Type
- List
(inner) blankNode(node, childPathopt) → {*}
Accepts a node and returns a copy of it with all children and all non-childPath
keys removed.
Essentially the minimum data structure required for the node.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
node |
* | The node to make blank. |
||
childPath |
ChildPath |
<optional> |
null
|
An Array or List of keys indicating where to find the node's children. |
Returns:
The blank node.
- Type
- *
(inner) nodePathToKeys(nodePath, childPathopt) → {List}
Turns a node's nodePath
and its childPath
into a full key path.
Example
nodePathToKeys(null, ['children']); // returns []
nodePathToKeys(['bob'], ['children']); // returns ['children', 'bob']
nodePathToKeys([0,1], ['children']); // returns ['children', 0, 'children', 1]
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
nodePath |
NodePath | A NodePath used to uniquely identify a node. |
||
childPath |
ChildPath |
<optional> |
null
|
An Array or List of keys indicating where to find each node's children from within each node. |
Returns:
- Type
- List
(inner) nodePathToKeysChildren(nodePath, childPathopt) → {List}
Turns a node's nodePath and its childPath into a full key path to the node's children.
Example
nodePathToKeysChildren(null, ['children']); // returns ['children']
nodePathToKeysChildren(['bob'], ['children']); // returns ['children', 'bob', children']
nodePathToKeysChildren([0,1], ['children']); // returns ['children', 0, 'children', 1, 'children']
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
nodePath |
NodePath | A NodePath used to uniquely identify a node. |
||
childPath |
ChildPath |
<optional> |
null
|
An Array or List of keys indicating where to find each node's children from within each node. |
Returns:
- Type
- List
(inner) isLeaf(node, childPathopt) → {boolean}
Accepts a node and returns a boolean indicating if the node is a leaf node (i.e. it has no children).
Example
const tree = fromJS({
name: "root",
children: [
{
name: "child 1",
children: [
{name: "grandchild 1"},
{name: "grandchild 2"}
]
},
{
name: "child 2",
children: []
}
]
});
isLeaf(tree.getIn(['children', 0]), ['childPath']); // returns false because child 1 has children
isLeaf(tree.getIn(['children', 1]), ['childPath']); // returns true because child 2 has no children
// note that normally deepGet is recommended instead of getIn for getting nodes from a tree
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
node |
* | The node to check. |
||
childPath |
ChildPath |
<optional> |
null
|
An Array or List of keys indicating where to find each node's children from within each node. |
Returns:
A boolean indicating if the node is a leaf node.
- Type
- boolean
(inner) pick(iterable, keys) → {Iterable}
Filter an Immutable Iterable
so it only retains any keys provided in the keys
param.
Similar to the pick function in Lodash.
Example
const map = Map({
a: "A",
b: "B",
c: "C",
d: "D"
});
pick(map, ['a', 'c']); // returns Map({a: "A", c: "C"});
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable | The |
keys |
Array | The iterable's keys to keep. |
Returns:
- Type
- Iterable