duck.html.components.core.childrenΒΆ

Module containing a specialized children list for managing child components insertion and deletion.

Module ContentsΒΆ

ClassesΒΆ

ChildrenList

A specialized list to manage child components of an InnerComponent.

APIΒΆ

class duck.html.components.core.children.ChildrenList(parent: duck.html.components.Component, initlist=None, skip_initlist_events: bool = False)[source]ΒΆ

Bases: duck.utils.eventlist.EventList

A specialized list to manage child components of an InnerComponent.

This class ensures that child components maintain correct parent-child relationships by updating references whenever a child is added or removed.

Inherits from: EventList: A custom list that provides hooks for item insertion and deletion.

Initialization

Initializes the ChildrenList with a reference to its parent component.

Parameters:
  • parent – The parent component to which children belong.

  • initlist – The initialization list to start with.

  • skip_initlist_events – Whether to skip calling event handler for each item in initlist.

Raises:

ComponentError – If the parent is not a valid InnerComponent.

_update_root_iterative(node: Component, new_root: Component)[source]ΒΆ

Iteratively update roots of a subtree. Uses a stack (DFS) to avoid recursion overhead.

on_delete_child(child: duck.html.components.Component)[source]ΒΆ

Handler called when a child is removed or replaced from the list.

Clears the parent and root references of the child component.

Parameters:

child – The child component being removed.

Raises:

ComponentError – If the child is not a valid component or not in the list.

on_new_child(child: duck.html.components.Component, component_loaded_check: bool = True)[source]ΒΆ

Attach a new child to this component, ensuring correct parent/root.