Raxol.Core.Runtime.Events.Dispatcher (Raxol v0.3.0)

View Source

Manages the application state (model) and dispatches events to the application's update/2 function. It also handles commands returned by update/2.

Summary

Functions

Broadcasts an event payload to all subscribers of a topic.

Returns a specification to start this module under a supervisor.

Dispatches an event to the appropriate handler based on event type and target.

Handles an application-level event and updates the application state.

Processes a system-level event that affects the runtime itself rather than the application logic.

Subscribes the calling process to a specific event topic.

Unsubscribes the calling process from a specific event topic.

Functions

broadcast(topic, payload)

@spec broadcast(atom(), map()) :: :ok | {:error, term()}

Broadcasts an event payload to all subscribers of a topic.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dispatch_event(event, state)

Dispatches an event to the appropriate handler based on event type and target.

Returns {:ok, updated_state} if the event was successfully handled, or {:error, reason, state} if something went wrong.

handle_event(event, state)

Handles an application-level event and updates the application state.

This is typically used for user interaction events like keyboard or mouse input.

process_system_event(event, state)

Processes a system-level event that affects the runtime itself rather than the application logic.

Examples include terminal resize events, focus events, or quit requests.

subscribe(topic)

@spec subscribe(atom()) :: :ok | {:error, term()}

Subscribes the calling process to a specific event topic.

unsubscribe(topic)

@spec unsubscribe(atom()) :: :ok | {:error, term()}

Unsubscribes the calling process from a specific event topic.