Pure functions for handling Phoenix LiveView events in A2UI.
Converts phx-click and phx-change event params into protocol-level
actions and data model updates. No socket state — fully unit-testable.
Summary
Functions
Applies an a2ui_input_change event to the surfaces map.
Builds an Action struct from a2ui_action event params.
Builds an Error struct from a2ui_error event params.
Functions
@spec apply_input_change(map(), A2UI.SurfaceManager.surfaces()) :: {:ok, A2UI.SurfaceManager.surfaces()} | {:error, atom()}
Applies an a2ui_input_change event to the surfaces map.
Extracts the input value from params, coerces it to match the existing data model type at the target path, and applies the update.
Returns {:ok, updated_surfaces} or {:error, reason}.
@spec build_action(map(), A2UI.SurfaceManager.surfaces()) :: {:ok, A2UI.Protocol.Messages.Action.t(), map()} | {:error, atom()}
Builds an Action struct from a2ui_action event params.
Returns {:ok, action, metadata} or {:error, reason}.
The metadata map includes:
:surface— the surface struct:send_data_model— whether the surface wants data model echoed back:data_model— the data model data (ifsend_data_modelis true)
@spec build_error(map()) :: {:ok, A2UI.Protocol.Messages.Error.t(), map()} | {:error, atom()}
Builds an Error struct from a2ui_error event params.
Returns {:ok, error, metadata} or {:error, reason}.