Fragment data shapes and the one Datastar SSE translator.
A fragment is the kernel's wire-format-neutral way of saying "push this to the browser":
{:fragment/kind :elements
:fragment/html "<form id=ix-001>…</form>"
:fragment/opts {…patch-elements! options…}}
{:fragment/kind :signals
:fragment/data {:foo 1}
:fragment/opts {}}
{:fragment/kind :script
:fragment/script "alert('hi')"
:fragment/opts {}}
{:fragment/kind :error
:fragment/html "<div id=ix-7e2 class=stube-error …>…</div>"
:fragment/opts {:selector "#ix-7e2" :patch-mode :outer}}
{:fragment/kind :close}
The kernel never touches Datastar; it just produces these maps. This
namespace is the single Datastar SDK boundary — it owns the patch-
mode keyword translation and turns fragments into SSE events. Before
it existed, the translator was duplicated between dev.zeko.stube.http and
dev.zeko.stube.server.
Fragment data shapes and the one Datastar SSE translator.
A *fragment* is the kernel's wire-format-neutral way of saying "push
this to the browser":
{:fragment/kind :elements
:fragment/html "<form id=ix-001>…</form>"
:fragment/opts {…patch-elements! options…}}
{:fragment/kind :signals
:fragment/data {:foo 1}
:fragment/opts {}}
{:fragment/kind :script
:fragment/script "alert('hi')"
:fragment/opts {}}
{:fragment/kind :error
:fragment/html "<div id=ix-7e2 class=stube-error …>…</div>"
:fragment/opts {:selector "#ix-7e2" :patch-mode :outer}}
{:fragment/kind :close}
The kernel never touches Datastar; it just produces these maps. This
namespace is the **single Datastar SDK boundary** — it owns the patch-
mode keyword translation and turns fragments into SSE events. Before
it existed, the translator was duplicated between [[dev.zeko.stube.http]] and
[[dev.zeko.stube.server]].Tell the SSE channel to close. Used after :end.
Tell the SSE channel to close. Used after `:end`.
(elements html)(elements html opts)Build an :elements fragment. opts is a kernel-level options map
({:selector ... :patch-mode ...}); leave it empty to let Datastar
morph by id.
Build an `:elements` fragment. `opts` is a kernel-level options map
(`{:selector ... :patch-mode ...}`); leave it empty to let Datastar
morph by id.(error html)(error html opts)Build an :error fragment. Wire-equivalent to :elements, but
tagged so observability layers and tests can distinguish a component
failure from a normal render.
Build an `:error` fragment. Wire-equivalent to `:elements`, but tagged so observability layers and tests can distinguish a component failure from a normal render.
(history-script mode url)Build a :script fragment that pushes or replaces the browser URL.
mode is :replace or :push; url is the new URL string.
Translates to a one-shot history.replaceState / history.pushState
call so no new SSE event type is needed.
Build a `:script` fragment that pushes or replaces the browser URL. `mode` is `:replace` or `:push`; `url` is the new URL string. Translates to a one-shot `history.replaceState` / `history.pushState` call so no new SSE event type is needed.
(push! sse-gen fragments)Push a sequence of fragments to an open Datastar SSE generator, holding the SSE lock so concurrent pushes never interleave.
Push a sequence of fragments to an open Datastar SSE generator, holding the SSE lock so concurrent pushes never interleave.
(push-keep-alive! sse-gen)Write a no-op SSE event to keep the connection alive across reverse-proxy idle timeouts. Datastar ignores any event type it does not know, so the client sees no DOM change; only the proxy sees activity on the channel.
Returns true on a successful write, false when the underlying channel is already closed (which is the signal to stop scheduling further heartbeats).
Write a no-op SSE event to keep the connection alive across reverse-proxy idle timeouts. Datastar ignores any event type it does not know, so the client sees no DOM change; only the proxy sees activity on the channel. Returns true on a successful write, false when the underlying channel is already closed (which is the signal to stop scheduling further heartbeats).
(script js)Build an :execute-script fragment.
Build an `:execute-script` fragment.
(signals m)Build a :signals fragment from a Clojure map.
Build a `:signals` fragment from a Clojure map.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |