TermUI.ComponentServer (TermUI v1.0.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 initialization timeouts, lifecycle callbacks, and its legacy
command tuples. It does not render the component and is not automatically
started or routed by TermUI.Runtime.
This server invokes init, mount, props-update, event, and unmount callbacks.
It does not delegate arbitrary GenServer calls or mailbox messages to a
component's optional handle_call/3 or handle_info/2. Its legacy timer
tuple schedules a message to the server but, without a custom host, that
message is unhandled; {:send, pid, message} is the safe built-in side effect.
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.
Returns a child specification for starting a component in 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 child_spec(module(), map(), keyword()) :: Supervisor.child_spec()
Returns a child specification for starting a component in a 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.