duck.html.components.core.system

Manages the registration and lifecycle of HTML components, and enables communication with the browser via WebSocket to dispatch events and execute JavaScript in real-time.

Module Contents

Classes

LivelyComponentSystem

LivelyComponentSystem class.

API

class duck.html.components.core.system.LivelyComponentSystem

LivelyComponentSystem class.

classmethod add_to_registry(uid: str, component: duck.html.components.Component) None

Add a component to the internal registry.

Parameters:
  • uid – The unique identifier for the component.

  • component – The component instance to register.

Raises:
classmethod get_from_registry(root_uid: str, uid: str, default: Optional[Any] = None) Optional[duck.html.components.Component]

Retrieve a component from the registry using its UID.

Parameters:
  • root_uid – The UID of the root component group.

  • uid – The unique identifier of the component.

  • default – The value to return if the component is not found.

Returns:

The component if found, otherwise the default value.

Return type:

Component | Any

classmethod get_html_tags() List[duck.html.components.templatetags.ComponentTag]

Returns loaded HTML component template tags defined in settings.py.

Raises:

ComponentSystemError – If any component cannot be imported or instantiated.

classmethod get_urlpatterns() List[duck.urls.URLPattern]

Returns the appropriate URL patterns for the whole system.

classmethod get_websocket_view_cls() Type

Returns the WebSocket view class responsible for handling communication between the server and the client, including event dispatching.

Returns:

The WebSocket view class used for client communication.

Return type:

Type

classmethod is_active() bool

Returns boolean on whether the component system is active.

registry: duck.utils.caching.InMemoryCache

‘InMemoryCache(…)’

Mapping of UIDs to components.

Format: {root_uid: {root_uid: component, child_uid: component, …}}

registry_lock

‘Lock(…)’

Lock for avoiding race conditions in multiple threads, especially in worker threads.