Lavash.Action.Runtime (Lavash v0.3.0-rc.3)

Copy Markdown View Source

Shared action execution runtime for both LiveView and Component.

This module contains the common logic for executing actions:

Runtime-specific operations (invoke, navigate, flash) remain in their respective runtime modules.

Summary

Functions

Execute side effect functions.

Apply set operations to state.

Build params map from action params spec and event params.

Coerce a value to the declared type of a state field.

Check if all guard conditions pass.

Functions

apply_effects(socket, effects, params)

Execute side effect functions.

Each effect has a function that receives the current full state. Effects are executed for their side effects; the socket is returned unchanged.

apply_runs(socket, action_name, runs, params, module)

Apply run operations to state.

Each run has a function (as quoted AST) that receives an assigns map (state + params merged) and returns updated assigns using Phoenix.Component.assign/3.

This enables proper change tracking via the assigns mechanism.

apply_sets(socket, sets, params, module)

Apply set operations to state.

Each set has a field and a value. The value can be:

  • A literal value
  • An rx() struct (reactive expression with @field syntax)
  • A function that receives %{params: params, state: state} (legacy)

Values are coerced to the field's declared type.

build_params(action_params, event_params)

Build params map from action params spec and event params.

Extracts named parameters from the event payload.

coerce_value(value, arg2)

Coerce a value to the declared type of a state field.

Handles:

  • nil state field (no coercion)
  • nil values (pass through)
  • Empty strings for non-string types (convert to nil)
  • String values parsed via Type.parse/2

guards_pass?(socket, module, guards)

Check if all guard conditions pass.

Guards are atoms referencing derived boolean fields that must all be true.