Shared DSL entity definitions used by both Lavash.Dsl (LiveView) and Lavash.Component.Dsl.
This module provides common entity definitions to reduce duplication between the two DSLs. Each DSL imports the entities it needs and may extend schemas with runtime-specific options.
Summary
Functions
Base schema for action entities.
Base schema for calculate entities.
Base schema for form entities.
Base schema fields shared by all state entities.
Effect entity for actions - runs a side effect function.
MapBy entity for actions — key-based array mutations.
Argument entity for read and derive blocks.
Run entity for actions - executes a function that transforms assigns.
Set entity for actions - assigns a value to a state field.
Submit entity for actions - submits a form.
Functions
Base schema for action entities.
Base schema for calculate entities.
Base schema for form entities.
Base schema fields shared by all state entities.
LiveView extends this with: :url from option, setter, encode, decode, required Component uses this with: :socket/:ephemeral from option only
Effect entity for actions - runs a side effect function.
MapBy entity for actions — key-based array mutations.
Finds items in an array by a key field and applies a transformation.
The @item variable references the matched item in the rx() expression.
Return :remove to filter the item out.
Argument entity for read and derive blocks.
Run entity for actions - executes a function that transforms assigns.
Server-only (plain function)
Use this for complex multi-field updates where individual set calls
would be cumbersome:
action :checkout do
run fn assigns ->
assigns
|> assign(:status, :processing)
|> assign(:submitted_at, DateTime.utc_now())
end
endTranspilable (with reads)
Add reads to declare state dependencies, enabling JavaScript transpilation
for optimistic client-side updates:
action :apply_discount do
run [:subtotal, :discount_rate], fn assigns ->
discount = assigns.subtotal * assigns.discount_rate
final = assigns.subtotal - discount
assigns
|> assign(:discount_amount, discount)
|> assign(:total, final)
end
endThe reads list declares which state fields the function depends on.
This enables the transpiler to generate equivalent JavaScript.
The function receives an assigns map (state + params merged) and should
use assign/3 to update fields. This ensures proper change tracking.
For simple single-field updates, prefer set with rx():
action :increment do
set :count, rx(@count + 1)
end
Set entity for actions - assigns a value to a state field.
The value can use @field syntax to reference state fields and params,
aligned with template syntax:
action :increment do
set :count, @count + 1
end
action :add_item do
params [:name]
set :items, @items ++ [@name]
endThe expression is captured at compile time and can be transpiled to JavaScript for optimistic client-side updates.
Submit entity for actions - submits a form.