Template and handler helpers imported by use Dstar.Page.
event/1,2— Datastar action expression targeting the page's own_eventroute, resolved client-side vialocation.pathname.connect/0,1— Datastar action expression opening the page's SSE stream.patch/3,4— render a function component into apatch_elementscall.
Summary
Functions
Builds the stream-connect expression for data-init /
data-on:online__window.
Builds a page-local Datastar action expression.
Renders a function component and pipes it to Dstar.Elements.patch/3.
Functions
Builds the stream-connect expression for data-init /
data-on:online__window.
connect()
#=> "@post(location.pathname, {retryMaxCount: Infinity})"
connect(include_search: true)
#=> "@post(location.pathname + location.search, {retryMaxCount: Infinity})"Options
:opts— override the options object (default"{retryMaxCount: Infinity}"):include_search— appendlocation.searchso query params reachhandle_connect(pages whose render depends on them, e.g.?step=).
Always emits @post — Dstar streams connect over POST.
Builds a page-local Datastar action expression.
event("increment")
#=> "@post(location.pathname.replace(/\/+$/, '') + '/_event/increment')"
event("remove", verb: :delete)
#=> "@delete(location.pathname.replace(/\/+$/, '') + '/_event/remove')"The URL is computed in the browser, so path params (workspace slugs,
ids) need no server-side threading. Event names become a single URL
path segment: they must not contain / or '.
Trailing slashes in the path are stripped client-side so pages mounted at "/" or visited with a trailing slash don't produce protocol-relative ("//") or double-slash URLs.
Options
:verb—:get | :post | :put | :patch | :delete(default:post):opts— raw JS object string appended as the action's options, e.g."{retryMaxCount: 5}"
Renders a function component and pipes it to Dstar.Elements.patch/3.
conn |> patch(&history/1, value: count)
conn |> patch(&item_card/1, [item: item], selector: "#row-1", mode: :outer)With no :selector, Datastar matches elements by their id attribute,
so the component's root element must carry one.