TermUI.ComponentServer (TermUI v0.2.0)
View SourceGenServer that manages the lifecycle of a component.
ComponentServer wraps any component implementing TermUI behaviours, managing its lifecycle stages: init, mount, update, and unmount. It handles prop validation, timeout enforcement, and command execution.
Lifecycle Stages
- Init - Create initial state from props
- Mount - Component enters active tree, ready for events
- Update - Props changed, state may update
- Unmount - Component removed, cleanup performed
Usage
Components are typically started via ComponentSupervisor:
{:ok, pid} = ComponentSupervisor.start_component(MyButton, %{label: "OK"})Direct usage:
{:ok, pid} = ComponentServer.start_link(MyButton, %{label: "OK"}, [])
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets the lifecycle state.
Gets the current props.
Gets the current component state.
Triggers the mount lifecycle stage.
Registers a lifecycle hook.
Sends an event to the component.
Starts a component server.
Triggers the unmount lifecycle stage.
Updates the component's props.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get_lifecycle(pid()) :: :initialized | :mounted | :unmounted
Gets the lifecycle state.
Gets the current props.
Gets the current component state.
Triggers the mount lifecycle stage.
Called when the component is added to the active component tree.
Registers a lifecycle hook.
Hook Types
:after_mount- Called after successful mount:before_unmount- Called before unmount cleanup:on_prop_change- Called when props change
Sends an event to the component.
@spec start_link(module(), map(), keyword()) :: GenServer.on_start()
Starts a component server.
Parameters
module- Component moduleprops- Initial propertiesopts- Options (:id,:timeout)
@spec unmount(pid()) :: :ok
Triggers the unmount lifecycle stage.
Called when the component is removed from the tree.
Updates the component's props.
Triggers the update callback if props have changed.