Lavash.Dsl (Lavash v0.4.0-rc.1)

Copy Markdown View Source

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 ID
  • form - create an AshPhoenix.Form from a resource
  • derive - custom computed values
  • actions - 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)
end

Form

Create an AshPhoenix.Form that auto-detects create vs update:

form :form, Product do
  data result(:product)
end

Form 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

Summary

Functions

actions(body)

(macro)