Lavash.LiveView (Lavash v0.4.0-rc.3)

Copy Markdown View Source

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
end

For the non-DSL on-ramp (reactive engine without the template transformer or optimistic JS), see Lavash.LiveView.Explicit.

Options

  • :extensions (list of module that adopts Spark.Dsl.Extension) - A list of DSL extensions to add to the Spark.Dsl

  • :otp_app (atom/0) - The otp_app to use for any application configurable options

  • :fragments (list of module/0) - Fragments to include in the Spark.Dsl. See the fragments guide for more.