Lavash.Form.Runtime (Lavash v0.4.0-rc.5)

Copy Markdown View Source

Shared form handling runtime for both LiveView and Component.

This module contains the common logic for form operations:

Summary

Functions

Broadcast mutation to all relevant PubSub topics.

Extract the Ash changeset from various form types.

Extract the Ash resource module from various form types.

Extract per-field errors from an Ash submit failure for storage in _server_errors state.

Resolve the Ash actor to pass to Lavash.Form.submit/2 for a submit :field action op.

Functions

broadcast_mutation(form)

Broadcast mutation to all relevant PubSub topics.

Uses the resource's notify_on configuration from Lavash.Resource extension to enable fine-grained invalidation based on filter combinations.

extract_changeset(cs)

Extract the Ash changeset from various form types.

Supports:

extract_resource(arg1)

Extract the Ash resource module from various form types.

Supports:

extract_submit_errors(arg1)

Extract per-field errors from an Ash submit failure for storage in _server_errors state.

Returns a map of %{"field_name" => ["error message", ...]}.

resolve_actor(assigns)

@spec resolve_actor(map() | Phoenix.LiveView.Socket.t()) :: any()

Resolve the Ash actor to pass to Lavash.Form.submit/2 for a submit :field action op.

Lookup order:

  1. socket.assigns[:actor] — the explicit, transport-agnostic prop. Components should accept this when they need to act on behalf of someone (they don't auto-receive :current_user because that's an on_mount injection, which only runs on LiveViews).

  2. socket.assigns[:current_user] — the conventional AshAuthentication assign. LiveViews under live_session ..., on_mount: AshAuthentication.LiveSession get this for free; for them submit Just Works without any host-side wiring.

  3. nil — no actor available. Submits that depend on an actor (relate_actor/1, policy checks, etc.) will fail with an Ash changeset error.