use macro that binds a Phoenix LiveView to a Caravela.Live.Domain
module.
Injects a default mount/3 (assigning the domain's initial state)
and a default handle_event/3 that dispatches to the domain's
on_event handlers. Also imports apply_updater/2,3, sugar around
Caravela.Live.Updater.apply/2,3 that looks up updaters by name on
the bound domain.
defmodule MyAppWeb.BookEditorLive do
use MyAppWeb, :live_view
use Caravela.Live.Template, domain: MyApp.BookEditorDomain
def render(assigns) do
~H"""
<LiveSvelte.render
name="library/BookEditor"
props={%{book: @book, saving: @saving}}
/>
"""
end
endThe Svelte component's pushEvent calls arrive as LiveView events
and are routed through the domain's on_event handlers. If no
handler matches, the default handle_event/3 lets the LiveView's
own (developer-written) clauses take over via Elixir's normal
clause-matching — this macro only adds a catch-all at the bottom.
Summary
Functions
Apply a named updater to the socket. The name is resolved against the
Caravela.Live.Domain module bound at use time.
Apply a named 2-arity updater with an event-payload argument.
Functions
Apply a named updater to the socket. The name is resolved against the
Caravela.Live.Domain module bound at use time.
def handle_event("save", _params, socket) do
{:noreply, socket |> apply_updater(:mark_saving)}
endRaises if the name isn't registered on the domain.
Apply a named 2-arity updater with an event-payload argument.
socket |> apply_updater(:set_book, book)