Raxol.UI.Components.Base.Lifecycle (Raxol v0.5.0)
View SourceProvides 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
@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 toevent
- The lifecycle event to record
Returns
The component with the added lifecycle event
Gets the lifecycle events recorded for a component.
Parameters
component
- The component to get events for
Returns
List of lifecycle events with timestamps
@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 mountprops
- Initial properties for the componentcontext
- The rendering context
Returns
The mounted component
@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 onevent
- The event to processcontext
- 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.
@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 rendercontext
- The rendering context
Returns
The rendered view representation and updated component state
@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 unmountcontext
- The rendering context
Returns
The unmounted component, typically for tracking/debugging only
@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 updateprops
- New properties to applycontext
- The rendering context
Returns
The updated component