wijjit.core.vdom.VNodeBuilder

class wijjit.core.vdom.VNodeBuilder(type, key=None)[source]

Mutable builder for constructing VNode trees during template execution.

Since VNodes are immutable, we use this mutable builder during template rendering when children are added incrementally. After template execution completes, call freeze() to convert to an immutable VNode tree.

Parameters:
  • type (str) – Element type name

  • key (str, optional) – Reconciliation key (typically the element id)

Variables:
  • type (str) – Element type name

  • key (str or None) – Reconciliation key

  • props (dict) – Mutable properties dictionary

  • children (list) – Mutable list of child VNodeBuilders

  • layout_spec (dict) – Layout specification (width, height, etc.) for this node

Examples

Build a tree incrementally:

>>> root = VNodeBuilder("VStack", key="main")
>>> root.props["spacing"] = 1
>>> child = VNodeBuilder("TextInput", key="name")
>>> child.props["placeholder"] = "Name"
>>> root.add_child(child)
>>> vnode = root.freeze()
>>> len(vnode.children)
1
__init__(type, key=None)[source]
Parameters:
Return type:

None

Methods

__init__(type[, key])

add_child(child)

Add a child VNodeBuilder.

freeze()

Convert to immutable VNode tree.

set_layout(**kwargs)

Set layout specification.

set_prop(name, value)

Set a property value.

add_child(child)[source]

Add a child VNodeBuilder.

Parameters:

child (VNodeBuilder) – Child node to add

Return type:

None

set_prop(name, value)[source]

Set a property value.

Parameters:
  • name (str) – Property name

  • value (Any) – Property value

Return type:

None

set_layout(**kwargs)[source]

Set layout specification.

Width and height are also copied to props (if not already set) so elements receive them as constructor parameters. This ensures elements like ImageView that need sizing information get it automatically.

For elements that need different values for layout vs element (e.g., LogView with borders where layout includes border space), call set_prop(“width”, …) BEFORE set_layout() to set the element’s internal dimensions separately from the layout dimensions.

Parameters:

**kwargs (Any) – Layout parameters (width, height, margin, etc.)

Return type:

None

freeze()[source]

Convert to immutable VNode tree.

Recursively freezes all children and preserves layout specification.

Returns:

Immutable VNode tree with layout_spec preserved

Return type:

VNode

Examples

>>> builder = VNodeBuilder("Button", key="ok")
>>> builder.props["label"] = "OK"
>>> builder.set_layout(width="fill", height=1)
>>> vnode = builder.freeze()
>>> isinstance(vnode, VNode)
True
>>> vnode.get_prop("label")
'OK'
>>> vnode.layout_spec_dict()
{'width': 'fill', 'height': 1}