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.
One route, any method and any event:
/ds/nds-connect/<component>/<component-id>/<event>. Every request opens a
connection: a new flow starts, the request's event runs through it, and its
render is sent down the stream. The flow is registered with the stream under
(component-id, user), replacing (and stopping) whatever was there, so a
reconnect or a reload simply takes over. The registered flow is what
send-event! puts server events on; their renders are pushed down the open
stream. Browser events after the open belong on /ds/nds/… (one-shot): a
request on the connect path would open a connection of its own.
The flow keeps nothing between events.
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. One route, any method and any event: /ds/nds-connect/<component>/<component-id>/<event>. Every request opens a connection: a new flow starts, the request's event runs through it, and its render is sent down the stream. The flow is registered with the stream under (component-id, user), replacing (and stopping) whatever was there, so a reconnect or a reload simply takes over. The registered flow is what `send-event!` puts server events on; their renders are pushed down the open stream. Browser events after the open belong on /ds/nds/… (one-shot): a request on the connect path would open a connection of its own. The flow keeps nothing between events.
(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)Async Ring handler for /ds/nds-connect/<component>/<component-id>/<event>,
on any HTTP method and with any event: every request opens a connection.
It answers with an SSE stream. On open, a new flow for the component starts
and is registered with the stream under (component-id, user), replacing
(and stopping the flow of) whatever was registered there; the request's
event runs through it and its render goes down the stream. On close, the
connection is unregistered and its flow stopped. The registered flow is
what send-event! sends to — browser events belong on /ds/nds/…
Async Ring handler for /ds/nds-connect/<component>/<component-id>/<event>, on any HTTP method and with any event: every request opens a connection. It answers with an SSE stream. On open, a new flow for the component starts and is registered with the stream under (component-id, user), replacing (and stopping the flow of) whatever was registered there; the request's event runs through it and its render goes down the stream. On close, the connection is unregistered and its flow stopped. The registered flow is what `send-event!` sends to — browser events belong on /ds/nds/…
(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 starts from the machine's initial state with params, 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 starts from the machine's initial state with `params`, 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 |