Lavash.State.Field (Lavash v0.3.0-rc.1)

Copy Markdown View Source

A mutable state field from an external source.

State fields declare where mutable state comes from:

  • :url - bidirectionally synced with the URL (query params or path)
  • :socket - survives reconnects via JS client sync
  • :ephemeral - socket-only, lost on disconnect (default)

Example

state :product_id, :integer, from: :url
state :form_params, :map, from: :ephemeral, default: %{}

Animated State

State fields can be animated, which adds phase tracking for enter/exit transitions:

state :panel_open, :boolean, animated: true
state :product_id, :any, animated: [async: :product, preserve_dom: true]

This generates additional fields:

  • {field}_phase - "idle" | "entering" | "loading" | "visible" | "exiting"

  • {field}_visible - calculated boolean, true when phase != "idle"
  • {field}_animating - calculated boolean, true during entering/exiting

Summary

Functions

Returns true if this field should be included in optimistic state.

Functions

optimistic?(arg1)

Returns true if this field should be included in optimistic state.

A field is optimistic if explicitly marked optimistic: true OR if it has animated set (animated implies optimistic — the phase machine requires client-side state tracking).