TermUI.ComponentRegistry (TermUI v0.2.0)
View SourceETS-based registry for component lookup.
The registry enables fast lookup of component processes by id, which is essential for event routing and focus management. Components register on mount and unregister on unmount.
Usage
# Register a component
ComponentRegistry.register(:my_button, pid, Button)
# Lookup by id
{:ok, pid} = ComponentRegistry.lookup(:my_button)
# Lookup by pid
{:ok, id} = ComponentRegistry.lookup_id(pid)
# List all
components = ComponentRegistry.list_all()
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all registrations.
Returns the count of registered components.
Gets all children of a component.
Gets full component info by id.
Gets the parent of a component.
Lists all registered components.
Looks up a component by id.
Looks up a component id by pid.
Registers a component in the registry.
Checks if a component is registered.
Sets the parent of a component for propagation.
Starts the component registry.
Unregisters a component from the registry.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear() :: :ok
Clears all registrations.
Mainly useful for testing.
@spec count() :: non_neg_integer()
Returns the count of registered components.
Gets all children of a component.
Returns
List of child component ids.
Gets full component info by id.
Returns
{:ok, %{id: term(), pid: pid(), module: module()}}- Component found{:error, :not_found}- Component not registered
Gets the parent of a component.
Returns
{:ok, parent_id}- Parent found (nil if root){:error, :not_found}- Component not in parent table
@spec list_all() :: [map()]
Lists all registered components.
Returns
List of %{id: term(), pid: pid(), module: module()}
Looks up a component by id.
Returns
{:ok, pid}- Component found{:error, :not_found}- Component not registered
Looks up a component id by pid.
Returns
{:ok, id}- Component found{:error, :not_found}- Component not registered
Registers a component in the registry.
Parameters
id- Unique identifier for the componentpid- Process pid of the componentmodule- Component module
Returns
:ok- Successfully registered{:error, :already_registered}- Id already taken
Checks if a component is registered.
Sets the parent of a component for propagation.
Parameters
id- Component idparent_id- Parent component id (or nil for root)
@spec start_link(keyword()) :: GenServer.on_start()
Starts the component registry.
@spec unregister(term()) :: :ok
Unregisters a component from the registry.
Parameters
id- Component identifier to unregister
Returns
:ok- Successfully unregistered (or wasn't registered)