Structures
#
DefinitionsBefore describing the API for this section, let's quickly mention what a node is and what a tree is in Build UI:
DEFINITION
- Tree: a structure that defines a normalized form of a tree hierarchy.
- Node: a structure that defines a normalized form of a tree node.
info
Build UI internally uses these node and tree structures to represent builder state. You will not need to think about this, though. The API also exposes a couple of functions to define these structures whenever you need to.
item()
#
#
Use ๐งA function used to instantiate a Node object.
#
Signature ๐๏ธ#
Example Usage ๐#
Parameters ๐ฅconfiguration: Object
An object with required type
key, and optional props
, and **__id__
(See itemid() for nuances) keys with their respective values.
#
Return Value ๐คA Node with the provided configuration. The node instance has the following methods:
with_meta: (meta: Object) => node: Node
A function to initialize the node with a list of indexes. If not provided, the default metadata for the node is an object with a key id and the assigned id as its value. It returns a node instance with the current node configuration plus the passed metadata
with_index: (...index: String) => node: Node
A function to initialize the node with a list of named indexes. It returns a node instance configured with the passed metadata. It returns a node instance with the current node configuration plus the passed named indexes.
with_index_list: (...index: String) => node: Node
A function to initialize the node with a list of named list indexes. It returns a node instance with the meta object assigned. It returns a node instance with the current node configuration plus the passed named index lists.
note
Please notice that the return value is not a plain JS object. It is an instance of a class.
branch()
#
#
Use ๐งA function used to instantiate a Tree object.
#
Signature ๐๏ธ#
Example Usage ๐#
Parameters ๐ฅnode: Node
The root node for the created tree.
#
Return Value ๐คA Tree with the provided configuration. The tree instance has the following methods:
with_child: (node: Node | tree: Tree) => tree: Tree
A function used to append a child to a tree. The child can itself be another tree.
note
Please notice that the return value is not a plain JS object. It is an instance of a class.
itemid()
#
#
Use ๐งA function used to generate a random id for a Node, using the __id__ property. You should only use it when necessary; otherwise an auto-generated is a better option.
caution
Use this function only when necessary. Having duplicate id's for Nodes in the builder state will cause Nodes to be overwritten.
#
Signature ๐๏ธ#
Example Usage ๐#
Parameters ๐ฅsize: int
The length of the id string.
#
Return Value ๐คA randomly generated string id.