Lavash.State (Lavash v0.4.0-rc.3)

Copy Markdown View Source

State hydration and management.

Summary

Functions

Hydrates fields declared from: :assigns by reading the named key out of socket.assigns at mount time.

Hydrates forms - creates implicit ephemeral state for form params.

Hydrates from: :session state from the Plug session map. Each field's :session_key (defaults to the field name as a string) is looked up; if absent, the field's :default is used. Session state is read once at mount and isn't re-read on subsequent events — like from: :ephemeral but seeded from the session at mount time.

Hydrates socket fields from connect params. Socket fields survive reconnects via JS client sync.

Functions

hydrate_assigns(socket, module)

Hydrates fields declared from: :assigns by reading the named key out of socket.assigns at mount time.

Runs AFTER any Phoenix on_mount hooks have completed (because hydrate_assigns is called inside Lavash.LiveView.Runtime.mount/4, which the runtime invokes from inside the LiveView's mount/3, by which point on_mount has run). So an assign that an on_mount installed — e.g. :current_user from AshAuthentication.LiveView — is present when this lifts it into lavash state.

One-way read. If the field is later mutated via lavash actions, the change does NOT propagate back to socket.assigns. The socket assign is the source of truth at mount; lavash state is the source of truth thereafter.

Resolution: field.assigns_key if set, otherwise field.name. Missing assigns fall back to field.default.

hydrate_ephemeral(socket, module)

hydrate_forms(socket, module)

Hydrates forms - creates implicit ephemeral state for form params.

hydrate_session(socket, module, session)

Hydrates from: :session state from the Plug session map. Each field's :session_key (defaults to the field name as a string) is looked up; if absent, the field's :default is used. Session state is read once at mount and isn't re-read on subsequent events — like from: :ephemeral but seeded from the session at mount time.

hydrate_socket(socket, module, connect_params)

Hydrates socket fields from connect params. Socket fields survive reconnects via JS client sync.

hydrate_url(socket, module, params)