wijjit.core.vdom.VNode

class wijjit.core.vdom.VNode(type, key=None, props=(), children=(), layout_spec=())[source]

Immutable description of a UI element.

VNodes are lightweight, immutable descriptions of what the UI should look like. They are compared by the Reconciler to determine what changes need to be made to the actual Element tree.

Parameters:
  • type (str) – Element type name (e.g., “TextInput”, “Button”, “VStack”)

  • key (str or None) – Stable identity for list reconciliation. Elements with matching keys are considered the “same” element and will be updated rather than replaced.

  • props (tuple of (str, Any) pairs) – Immutable properties as a tuple of key-value pairs. Stored as tuple for hashability.

  • children (tuple of VNode) – Child VNodes for container elements.

  • layout_spec (tuple of (str, Any) pairs) – Layout specification (width, height, margin, padding, etc.) as immutable tuple of key-value pairs. Used to rebuild LayoutNode tree from reconciled elements.

Variables:
  • type (str) – Element type name

  • key (str or None) – Reconciliation key

  • props (tuple) – Immutable props

  • children (tuple) – Child VNodes

  • layout_spec (tuple) – Immutable layout specification

Notes

VNodes are frozen dataclasses, making them immutable and hashable. This ensures reliable comparison during diffing.

Examples

Create a simple VNode:

>>> vnode = VNode.create("Button", key="submit", props={"label": "Submit"})
>>> vnode.type
'Button'
>>> dict(vnode.props)
{'label': 'Submit'}

Create a container with children:

>>> child1 = VNode.create("TextInput", key="name")
>>> child2 = VNode.create("Button", key="submit")
>>> container = VNode.create("VStack", children=[child1, child2])
>>> len(container.children)
2
__init__(type, key=None, props=(), children=(), layout_spec=())
Parameters:
Return type:

None

Methods

__init__(type[, key, props, children, ...])

create(type[, key, props, children, layout_spec])

Factory method for creating VNodes with dict/list convenience.

get_prop(name[, default])

Get a property value by name.

layout_spec_dict()

Convert layout_spec tuple to dictionary.

props_dict()

Convert props tuple to dictionary.

Attributes

children

key

layout_spec

props

type

type: str
key: str | None = None
props: tuple[tuple[str, Any], ...] = ()
children: tuple[VNode, ...] = ()
layout_spec: tuple[tuple[str, Any], ...] = ()
static create(type, key=None, props=None, children=None, layout_spec=None)[source]

Factory method for creating VNodes with dict/list convenience.

Parameters:
  • type (str) – Element type name

  • key (str, optional) – Reconciliation key

  • props (dict, optional) – Properties as a dictionary (will be converted to sorted tuple)

  • children (list, optional) – Child VNodes as a list (will be converted to tuple)

  • layout_spec (dict, optional) – Layout specification (will be converted to sorted tuple)

Returns:

New immutable VNode instance

Return type:

VNode

Examples

>>> vnode = VNode.create(
...     "TextInput",
...     key="username",
...     props={"placeholder": "Enter username", "width": 30}
... )
get_prop(name, default=None)[source]

Get a property value by name.

Parameters:
  • name (str) – Property name to look up

  • default (Any, optional) – Value to return if property not found

Returns:

Property value or default

Return type:

Any

Examples

>>> vnode = VNode.create("Button", props={"label": "Click"})
>>> vnode.get_prop("label")
'Click'
>>> vnode.get_prop("disabled", False)
False
props_dict()[source]

Convert props tuple to dictionary.

Returns:

Props as a mutable dictionary

Return type:

dict

Examples

>>> vnode = VNode.create("Button", props={"label": "OK", "width": 10})
>>> vnode.props_dict()
{'label': 'OK', 'width': 10}
layout_spec_dict()[source]

Convert layout_spec tuple to dictionary.

Returns:

Layout spec as a mutable dictionary

Return type:

dict

Examples

>>> vnode = VNode.create("Button", layout_spec={"width": "fill", "height": 1})
>>> vnode.layout_spec_dict()
{'width': 'fill', 'height': 1}