wijjit.core.element_registry.ElementRegistry
- class wijjit.core.element_registry.ElementRegistry[source]
Registry mapping VNode types to Element factories.
The ElementRegistry maintains a mapping from VNode type strings (like “TextInput”, “Button”) to Element class constructors. During reconciliation, when a new element needs to be created, the registry provides the appropriate factory function.
- Variables:
_factories (
dict) – Mapping of type name to Element class/factory
Examples
>>> registry = ElementRegistry() >>> from wijjit.core.vdom import VNode >>> vnode = VNode.create("Button", props={"label": "OK"}) >>> element = registry.create_element(vnode) >>> element.__class__.__name__ 'Button'
Methods
__init__()create_element(vnode)Create an Element instance from a VNode.
get_factory(type_name)Get the factory for a type name.
has_type(type_name)Check if a type is registered.
List all registered type names.
register(type_name, factory)Register a custom element type.
unregister(type_name)Unregister an element type.
- register(type_name, factory)[source]
Register a custom element type.
- Parameters:
- Return type:
None
Examples
>>> registry = ElementRegistry() >>> class CustomWidget(Element): ... pass >>> registry.register("CustomWidget", CustomWidget)
- create_element(vnode)[source]
Create an Element instance from a VNode.
- Parameters:
vnode (
VNode) – Virtual node describing the element- Returns:
New Element instance
- Return type:
Element- Raises:
KeyError – If vnode.type is not registered
ValueError – If element creation fails
Examples
>>> from wijjit.core.vdom import VNode >>> registry = ElementRegistry() >>> vnode = VNode.create("TextInput", props={"id": "name", "placeholder": "Name"}) >>> element = registry.create_element(vnode) >>> element.id 'name'