Use this module to create a Lavash-powered LiveView.
Declares the DSL surface (state, calculate, read, form, actions,
etc.), imports the ~L sigil, and wires the template transformer +
optimistic JS hook.
Example
defmodule MyAppWeb.ProfileLive do
use Lavash.LiveView
state :user_id, :integer, from: :url, required: true
state :tab, :string, from: :url, default: "overview"
state :editing, :boolean, default: false
read :user, MyApp.Accounts.User do
id state(:user_id)
async true
end
actions do
action :change_tab, [:tab] do
set :tab, rx(@tab)
end
end
render fn assigns ->
~L"""
<div>
<h1>{@user.name}</h1>
<button phx-click="change_tab" phx-value-tab="overview">Overview</button>
</div>
"""
end
endFor the non-DSL on-ramp (reactive engine without the template
transformer or optimistic JS), see Lavash.LiveView.Explicit.
Options
:extensions(list of module that adoptsSpark.Dsl.Extension) - A list of DSL extensions to add to theSpark.Dsl:otp_app(atom/0) - The otp_app to use for any application configurable options:fragments(list ofmodule/0) - Fragments to include in theSpark.Dsl. See the fragments guide for more.