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 (
strorNone) – Stable identity for list reconciliation. Elements with matching keys are considered the “same” element and will be updated rather than replaced.props (
tupleof(str,Any) pairs) – Immutable properties as a tuple of key-value pairs. Stored as tuple for hashability.children (
tupleofVNode) – Child VNodes for container elements.layout_spec (
tupleof(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:
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=())
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.
Convert layout_spec tuple to dictionary.
Convert props tuple to dictionary.
Attributes
- 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 namekey (
str, optional) – Reconciliation keyprops (
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:
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 updefault (
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