wijjit.core.reconciler.Reconciler

class wijjit.core.reconciler.Reconciler(registry)[source]

Reconciles old and new VNode trees, producing a patched Element tree.

The Reconciler implements a React-style diffing algorithm that:

  1. Compares old and new VNode trees

  2. Identifies what changed (creates, deletes, updates)

  3. Patches existing Elements in place where possible

  4. Creates new Elements only when necessary

  5. Preserves ephemeral state (cursor, scroll, selection) across re-renders, while letting a template deliberately drive it: a controllable ephemeral prop whose bound value changed this render is applied over the preserved snapshot (“state wins, else preserve”). See _diff_controlled_ephemeral().

Parameters:

registry (ElementRegistry) – Registry for creating new Element instances

Variables:
  • registry (ElementRegistry) – Element factory registry

  • _element_cache (dict) – Cache of key -> Element for reusing elements

Examples

>>> from wijjit.core.vdom import VNode
>>> from wijjit.core.element_registry import ElementRegistry
>>> registry = ElementRegistry()
>>> reconciler = Reconciler(registry)
>>> old_tree = VNode.create("Button", key="btn", props={"label": "Old"})
>>> new_tree = VNode.create("Button", key="btn", props={"label": "New"})
>>> root, elements = reconciler.reconcile(old_tree, new_tree)
>>> root.label  # Element was updated, not replaced
'New'
__init__(registry)[source]
Parameters:

registry (ElementRegistry)

Return type:

None

Methods

__init__(registry)

clear_cache()

Clear the element cache.

get_cached_element(key)

Get an element from the cache by key.

reconcile(old_tree, new_tree)

Reconcile old and new VNode trees.

reconcile(old_tree, new_tree)[source]

Reconcile old and new VNode trees.

Parameters:
  • old_tree (VNode or None) – Previous VNode tree (None on first render)

  • new_tree (VNode or None) – New VNode tree (None to unmount everything)

Returns:

(root_element, flat_element_list) - root_element: Root Element of the tree (None if new_tree is None) - flat_element_list: Flattened list of all Elements for event handling

Return type:

tuple

clear_cache()[source]

Clear the element cache.

Call this when switching views or when a full re-render is needed.

Return type:

None

get_cached_element(key)[source]

Get an element from the cache by key.

Parameters:

key (str) – Element key

Returns:

Cached element, or None if not found

Return type:

Element or None