Handler for establishing persistent SSE connections to component instances.
Manages a !connections atom that tracks, per (component-id, user-id), the
open SSE stream AND the component flow (taia.ds.datastar.use-cases.process-event)
that lives as long as it.
On connection open, the flow is started (holding the ctx between events), the INIT event runs through it, and its render is sent down the stream. Afterwards:
handler-connected-component-event) runs through
the SAME flow and answers with the render, like a default component;send-event! puts a server event on the flow, and its render is pushed
down the open stream.Handler for establishing persistent SSE connections to component instances. Manages a `!connections` atom that tracks, per (component-id, user-id), the open SSE stream AND the component flow (`taia.ds.datastar.use-cases.process-event`) that lives as long as it. On connection open, the flow is started (holding the ctx between events), the INIT event runs through it, and its render is sent down the stream. Afterwards: - a POST on the same path (`handler-connected-component-event`) runs through the SAME flow and answers with the render, like a default component; - `send-event!` puts a server event on the flow, and its render is pushed down the open stream.
(connections)The open streams, as {component-id [user-id …]} — who send-ui! and
send-event! can reach right now. For the REPL and diagnostics.
The open streams, as {component-id [user-id …]} — who `send-ui!` and
`send-event!` can reach right now. For the REPL and diagnostics.(handle-ui-event [component-id user-id component-responses mulog-ctx])Handles a single message from !ui-chan.
Expects [component-id user-id component-responses mulog-ctx] where
component-responses is a seq of effect vectors like [[:patch [:div ...] opts]]
and mulog-ctx (optional) is the caller's mulog context captured by send-ui!,
re-established here so the per-write ::sse-write spans nest under the
caller's trace (the agent turn) instead of being context-less.
Handles a single message from !ui-chan. Expects [component-id user-id component-responses mulog-ctx] where component-responses is a seq of effect vectors like [[:patch [:div ...] opts]] and mulog-ctx (optional) is the caller's mulog context captured by send-ui!, re-established here so the per-write `::sse-write` spans nest under the caller's trace (the agent turn) instead of being context-less.
(handler-connected-component-connect req respond _raise)(handler-connected-component-event req)(handler-connected-component-event req respond raise)Ring handler (both arities) for an event POSTed to a connected component's path (/ds/nds-connect/<component>/<component-id>/<event>): it runs through the flow that lives with the user's open stream.
Ring handler (both arities) for an event POSTed to a connected component's path (/ds/nds-connect/<component>/<component-id>/<event>): it runs through the flow that lives with the user's open stream.
(register-connection! component component-id sse-gen logged-user)(register-connection! _component
component-id
sse-gen
logged-user
component-flow)Registers sse-gen (and its component flow, when given) under (component-id, user-id). A reconnect replaces the previous entry; the replaced entry's flow is stopped here, since its stream's late on-close will no longer match the registry.
Registers sse-gen (and its component flow, when given) under (component-id, user-id). A reconnect replaces the previous entry; the replaced entry's flow is stopped here, since its stream's late on-close will no longer match the registry.
(send-event! component-id user-id event-name params)Puts a server event on the flow of the connection (component-id, user-id): it transitions from the ctx the flow holds, and its render is pushed down that connection's stream. The caller's trace rides along. Returns true when the event was queued, false when there is no open connection with a flow.
Puts a server event on the flow of the connection (component-id, user-id): it transitions from the ctx the flow holds, and its render is pushed down that connection's stream. The caller's trace rides along. Returns true when the event was queued, false when there is no open connection with a flow.
(send-heartbeat!)Enqueues an inert keep-alive write to every open connection, reusing the per-user write channel + stale-drop semantics of send-replies!.
Enqueues an inert keep-alive write to every open connection, reusing the per-user write channel + stale-drop semantics of send-replies!.
(send-replies! component-id user-id sse-gen component-responses)Dispatches a seq of component-responses to a single SSE client. Each response is a vector like [:patch elements options]. Writes are enqueued onto the user's channel for non-blocking delivery.
Effect types:
Dispatches a seq of component-responses to a single SSE client. Each response is a vector like [:patch elements options]. Writes are enqueued onto the user's channel for non-blocking delivery. Effect types: - :patch — send to this specific user only - :broadcast — send to ALL users currently connected under component-id
(send-ui! component-id user-id component-responses)Puts component-responses onto !ui-chan for async delivery to the specific SSE client identified by component-id and user-id. component-responses is a seq of effect vectors, e.g. [[:patch [:div#foo "hello"] {:d*/selector "#foo"}]]. The caller's mulog context rides along: the channel hop would otherwise drop it and every write would trace as its own root.
Puts component-responses onto !ui-chan for async delivery to the specific
SSE client identified by component-id and user-id.
component-responses is a seq of effect vectors,
e.g. [[:patch [:div#foo "hello"] {:d*/selector "#foo"}]].
The caller's mulog context rides along: the channel hop would otherwise
drop it and every write would trace as its own root.A context-less write (heartbeat) slower than this, or one that waited longer
than this in the queue, is reported as its own ::sse-write-slow span so it
reaches Tempo without tracing every 15 s heartbeat.
A context-less write (heartbeat) slower than this, or one that waited longer than this in the queue, is reported as its own `::sse-write-slow` span so it reaches Tempo without tracing every 15 s heartbeat.
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 |