Raxol.UI.Components.Base.Lifecycle (Raxol v0.2.0)

View Source

Provides component lifecycle hooks and management for UI components.

This module handles:

  • Component mounting and initialization
  • Update propagation to components
  • Component unmounting and cleanup
  • Lifecycle event tracking

Summary

Functions

Adds a lifecycle event to the component for debugging purposes.

Gets the lifecycle events recorded for a component.

Mounts a component, initializing its state and triggering mount-time effects.

Processes an event on a component.

Renders a component, creating its view representation.

Unmounts a component, allowing it to clean up resources.

Updates a component with new props.

Functions

add_lifecycle_event(component, event)

@spec add_lifecycle_event(Raxol.UI.Components.Base.Component.t(), term()) ::
  Raxol.UI.Components.Base.Component.t()

Adds a lifecycle event to the component for debugging purposes.

Parameters

  • component - The component to add the event to
  • event - The lifecycle event to record

Returns

The component with the added lifecycle event

get_lifecycle_events(component)

@spec get_lifecycle_events(Raxol.UI.Components.Base.Component.t()) :: [
  {term(), integer()}
]

Gets the lifecycle events recorded for a component.

Parameters

  • component - The component to get events for

Returns

List of lifecycle events with timestamps

mount(component, props \\ %{}, context \\ %{})

@spec mount(Raxol.UI.Components.Base.Component.t(), map(), map()) ::
  Raxol.UI.Components.Base.Component.t()

Mounts a component, initializing its state and triggering mount-time effects.

Parameters

  • component - The component to mount
  • props - Initial properties for the component
  • context - The rendering context

Returns

The mounted component

process_event(component, event, context)

@spec process_event(Raxol.UI.Components.Base.Component.t(), map(), map()) ::
  {:update, Raxol.UI.Components.Base.Component.t()}
  | {:handled, Raxol.UI.Components.Base.Component.t()}
  | :passthrough

Processes an event on a component.

Parameters

  • component - The component to process the event on
  • event - The event to process
  • context - The event context

Returns

{:update, updated_component} if the component state changed, {:handled, component} if the event was handled but state didn't change, :passthrough if the event wasn't handled by the component.

render(component, context)

@spec render(Raxol.UI.Components.Base.Component.t(), map()) ::
  {Raxol.UI.Components.Base.Component.t(), map()}

Renders a component, creating its view representation.

This is a wrapper around the component's render function that ensures consistent handling of the rendering process.

Parameters

  • component - The component to render
  • context - The rendering context

Returns

The rendered view representation and updated component state

unmount(component, context \\ %{})

@spec unmount(Raxol.UI.Components.Base.Component.t(), map()) ::
  Raxol.UI.Components.Base.Component.t()

Unmounts a component, allowing it to clean up resources.

Parameters

  • component - The component to unmount
  • context - The rendering context

Returns

The unmounted component, typically for tracking/debugging only

update(component, props, context \\ %{})

@spec update(Raxol.UI.Components.Base.Component.t(), map(), map()) ::
  Raxol.UI.Components.Base.Component.t()

Updates a component with new props.

Parameters

  • component - The component to update
  • props - New properties to apply
  • context - The rendering context

Returns

The updated component