The Spark DSL extension for Lavash Components.
Components have the same capabilities as LiveViews:
prop- passed from parent (read-only)state- internal state (socket or ephemeral)read- async load an Ash resource by IDform- create an AshPhoenix.Form from a resourcecalculate- reactive computed value via rx()actions- state transformers (set, run, update, effect, submit)
All declared fields are automatically projected as assigns.
Example:
defmodule MyApp.ProductEditModal do
use Lavash.Component
alias MyApp.Catalog.Product
prop :product_id, :integer
state :submitting, :boolean, default: false
read :product, Product do
id prop(:product_id)
end
form :edit_form, Product do
data result(:product)
end
actions do
action :save do
set :submitting, true
submit :edit_form, on_success: :save_success, on_error: :save_failed
end
action :save_success do
set :submitting, false
end
action :save_failed do
set :submitting, false
end
end
end