Skip to content

Lifecycles

MountLifeCycles

Bases: HydratorVirtualDomAdapter

This class provides lifecycle methods for components that are mounted to the DOM.

It inherits from the HydratorVirtualDomAdapter class, which provides methods for interacting with the virtual DOM.

Source code in zenaura/client/dom/lifecycles/mount.py
class MountLifeCycles(
    HydratorVirtualDomAdapter
):
    """
    This class provides lifecycle methods for components that are mounted to the DOM.

    It inherits from the `HydratorVirtualDomAdapter` class, which provides methods for interacting with the virtual DOM.
    """

    async def attached(self, comp) -> None:
        """
        This method is called after the component is mounted to the DOM.

        It allows the component to perform any necessary actions after it has been added to the DOM, such as:

        - Initializing state
        - Setting up event listeners
        - Making API calls
        - Performing animations

        Args:
            comp: An instance of the Component class.

        Returns:
            None
        """

        if hasattr(comp, 'attached'):
            await comp.attached()

attached(comp) async

This method is called after the component is mounted to the DOM.

It allows the component to perform any necessary actions after it has been added to the DOM, such as:

  • Initializing state
  • Setting up event listeners
  • Making API calls
  • Performing animations

Parameters:

Name Type Description Default
comp

An instance of the Component class.

required

Returns:

Type Description
None

None

Source code in zenaura/client/dom/lifecycles/mount.py
async def attached(self, comp) -> None:
    """
    This method is called after the component is mounted to the DOM.

    It allows the component to perform any necessary actions after it has been added to the DOM, such as:

    - Initializing state
    - Setting up event listeners
    - Making API calls
    - Performing animations

    Args:
        comp: An instance of the Component class.

    Returns:
        None
    """

    if hasattr(comp, 'attached'):
        await comp.attached()

RenderLifeCycle

This class provides lifecycle methods for components that are rendered to the DOM.

It allows components to perform actions before and after they are updated and re-rendered in the DOM.

Source code in zenaura/client/dom/lifecycles/render.py
class RenderLifeCycle:
    """
    This class provides lifecycle methods for components that are rendered to the DOM.

    It allows components to perform actions before and after they are updated and re-rendered in the DOM.

    Attributes:
        None
    """

    async def on_mutation(self, comp) -> None:
        """
        This method is called after the component is updated in the DOM and re-rendered.

        It allows the component to perform any necessary actions before the update is applied, such as:

        - Updating state based on new props
        - Setting up event listeners
        - Making API calls
        - Performing animations

        Args:
            comp: An instance of the Component class.

        Returns:
            None
        """

        # Perform operations before updating
        if hasattr(comp, 'on_mutation'):
            await comp.on_mutation()

    async def on_settled(self, comp) -> None:
        """
        This method is called after the component is updated in the DOM and re-rendered.

        It allows the component to perform any necessary actions after the update is applied, such as:

        - Focusing on an input element
        - Scrolling to a specific position
        - Triggering custom events

        Args:
            comp: An instance of the Component class.

        Returns:
            None
        """

        # Perform operations after updating
        if hasattr(comp, 'on_settled'):
            await comp.on_settled()

on_mutation(comp) async

This method is called after the component is updated in the DOM and re-rendered.

It allows the component to perform any necessary actions before the update is applied, such as:

  • Updating state based on new props
  • Setting up event listeners
  • Making API calls
  • Performing animations

Parameters:

Name Type Description Default
comp

An instance of the Component class.

required

Returns:

Type Description
None

None

Source code in zenaura/client/dom/lifecycles/render.py
async def on_mutation(self, comp) -> None:
    """
    This method is called after the component is updated in the DOM and re-rendered.

    It allows the component to perform any necessary actions before the update is applied, such as:

    - Updating state based on new props
    - Setting up event listeners
    - Making API calls
    - Performing animations

    Args:
        comp: An instance of the Component class.

    Returns:
        None
    """

    # Perform operations before updating
    if hasattr(comp, 'on_mutation'):
        await comp.on_mutation()

on_settled(comp) async

This method is called after the component is updated in the DOM and re-rendered.

It allows the component to perform any necessary actions after the update is applied, such as:

  • Focusing on an input element
  • Scrolling to a specific position
  • Triggering custom events

Parameters:

Name Type Description Default
comp

An instance of the Component class.

required

Returns:

Type Description
None

None

Source code in zenaura/client/dom/lifecycles/render.py
async def on_settled(self, comp) -> None:
    """
    This method is called after the component is updated in the DOM and re-rendered.

    It allows the component to perform any necessary actions after the update is applied, such as:

    - Focusing on an input element
    - Scrolling to a specific position
    - Triggering custom events

    Args:
        comp: An instance of the Component class.

    Returns:
        None
    """

    # Perform operations after updating
    if hasattr(comp, 'on_settled'):
        await comp.on_settled()