The Spark DSL extension for Lavash LiveViews.
Provides declarative state management with Reactor-inspired syntax:
state- mutable state from external sources (URL, socket, ephemeral)read- async load an Ash resource by IDform- create an AshPhoenix.Form from a resourcederive- custom computed valuesactions- state transformers
All declared fields are automatically projected as assigns.
State
State fields are mutable state from external sources:
state :product_id, :integer, from: :url
state :form_params, :map, from: :ephemeral, default: %{}Read
Load an Ash resource by ID (async by default):
read :product, Product do
id state(:product_id)
endForm
Create an AshPhoenix.Form that auto-detects create vs update:
form :form, Product do
data result(:product)
endForm params are implicit - :form_params is auto-created and bound to phx-change events.
You can override with explicit params if needed: params state(:custom_params)
Example
defmodule MyApp.ProductEditLive do
use Lavash.LiveView
state :product_id, :integer, from: :url
read :product, Product do
id state(:product_id)
end
form :form, Product do
data result(:product)
end
actions do
action :save do
submit :form
navigate "/products"
end
end
end