Liking cljdoc? Tell your friends :D

taia.ds.datastar.adapters.handlers.connected-component-handler

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.
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.
raw docstring

taia.ds.datastar.adapters.handlers.default-component-handler

Dynamic endpoint handler for component events. Handles routes like /:component/:component-id/:event.

The event runs through a component flow of its own (process-component-event: request → message → the process-event use case); the response shaping (render-response, error-response) lives in taia.ds.datastar.adapters.handlers.response. This namespace only owns the Ring handler entrypoint.

Dynamic endpoint handler for component events.
Handles routes like /:component/:component-id/:event.

The event runs through a component flow of its own
(`process-component-event`: request → message → the process-event use
case); the response
shaping (`render-response`, `error-response`) lives in
`taia.ds.datastar.adapters.handlers.response`. This namespace only owns the
Ring handler entrypoint.
raw docstring

taia.ds.datastar.adapters.handlers.discovery-cache

Lookup cache for Datastar component resolution.

WHAT IS CACHED: the resolved NAMESPACE SYMBOLS, never the vars.

The expensive half of discovery/discover-component is the search-path scan: for "chat.chat" an earlier prefix such as my.app.admin.components does not hold it, so require throws a FileNotFoundException (stack trace and all) before the scan falls through to my.app.components.chat.chat. That answer never changes for a given [component-name controller-name] pair, so it is what we store. Turning the cached symbols back into vars is a namespace-map lookup with no I/O, and it is done on every hit — which keeps the cache REPL-safe: caching the vars themselves would survive an ordinary defn re-evaluation (same var object, new root binding) but go stale on remove-ns / :reload-all, which mint brand-new var objects.

Deliberately NOT cache.interface: that component's contract is EDN-serializable values under a TTL, and it would add a cross-component dependency to the intentionally generic datastar component.

Lookup cache for Datastar component resolution.

WHAT IS CACHED: the resolved NAMESPACE SYMBOLS, never the vars.

The expensive half of `discovery/discover-component` is the search-path scan:
for "chat.chat" an earlier prefix such as `my.app.admin.components` does not hold it, so
`require` throws a FileNotFoundException (stack trace and all) before the scan
falls through to `my.app.components.chat.chat`. That answer never
changes for a given [component-name controller-name] pair, so it is what we
store. Turning the cached symbols back into vars is a namespace-map lookup
with no I/O, and it is done on every hit — which keeps the cache REPL-safe:
caching the vars themselves would survive an ordinary `defn` re-evaluation
(same var object, new root binding) but go stale on `remove-ns` / `:reload-all`,
which mint brand-new var objects.

Deliberately NOT `cache.interface`: that component's contract is
EDN-serializable values under a TTL, and it would add a cross-component
dependency to the intentionally generic `datastar` component.
raw docstring

taia.ds.datastar.adapters.handlers.observer

Pluggable observation hook for the two Datastar entry points (/ds/nds and /ds/nds-connect). datastar stays metrics-agnostic: it reports plain maps to ONE observer fn installed at startup (taia.ds.datastar.interface/set-observer!), and does nothing at all when none is set.

Observations:

  • {:type :event :route :nds|:nds-connect|:nds-connect-event :component c :event e :outcome :ok|:error :seconds s}
  • {:type :sse-opened :component c}
  • {:type :sse-closed :component c :seconds lifetime}

No component-id is ever reported — every instance of a component is one series. And the reported values are BOUNDED: component and event come from the URL, so anyone could mint new ones. A component counts only once discovery has resolved it (the discovery cache holds it), an event only when that component's machine declares it; everything else collapses to unknown-component / other-event.

Pluggable observation hook for the two Datastar entry points
(/ds/nds and /ds/nds-connect). `datastar` stays metrics-agnostic: it
reports plain maps to ONE observer fn installed at startup
(`taia.ds.datastar.interface/set-observer!`), and does nothing at all when none is set.

Observations:
- {:type :event :route :nds|:nds-connect|:nds-connect-event :component c :event e
   :outcome :ok|:error :seconds s}
- {:type :sse-opened :component c}
- {:type :sse-closed :component c :seconds lifetime}

No component-id is ever reported — every instance of a component is one
series. And the reported values are BOUNDED: component and event come
from the URL, so anyone could mint new ones. A component counts only once
discovery has resolved it (the discovery cache holds it), an event only
when that component's machine declares it; everything else collapses to
`unknown-component` / `other-event`.
raw docstring

taia.ds.datastar.adapters.handlers.request

From a Ring request to the plain event message a component's flow takes (see taia.ds.datastar.use-cases.process-event.common). This is the only place that knows where Datastar puts things in a request: the event's params, the component's slice of the signal store, the logged user.

From a Ring request to the plain event message a component's flow takes
(see `taia.ds.datastar.use-cases.process-event.common`). This is the only
place that knows where Datastar puts things in a request: the event's
params, the component's slice of the signal store, the logged user.
raw docstring

taia.ds.datastar.domain.ctx

The component context: how it is built from what the client sent, and how removed memory keys become client-side signal removals. Pure functions over plain data: no request, no channels.

The component context: how it is built from what the client sent, and how
removed memory keys become client-side signal removals. Pure functions over plain
data: no request, no channels.
raw docstring

taia.ds.datastar.domain.event

An event against a component's state machine: its keyword, whether it is one of Datastar's own, and the transition it causes. Pure: the machine's actions are the component's, and tracing hooks are passed in by the caller.

An event against a component's state machine: its keyword, whether it is
one of Datastar's own, and the transition it causes. Pure: the machine's
actions are the component's, and tracing hooks are passed in by the caller.
raw docstring

taia.ds.datastar.domain.schemas

Malli schemas for the Datastar component pipeline context.

Malli schemas for the Datastar component pipeline context.
raw docstring

taia.ds.datastar.use-cases.process-event

The use case: process a component's event. It runs as a clojure.core.async.flow of two procs, each in its own namespace:

in-chan ──▶ :controller ──:to-view──▶ :view ──▶ out-chan (state machine) (render) process-event.controller process-event.view

The messages are described in process-event.common. Everything here is plain data in and out: the caller resolves the component (its machine and render fn, as vars) and turns a request into a message (adapters); the rules about the ctx and the transition are the domain's.

Two lifetimes:

  • a DEFAULT component's event gets a flow of its own (process-event): put the event, take the render or time out, stop the flow;
  • a CONNECTED component's flow lives as long as its SSE stream (start-flow!), so a later event — a browser POST or a server send-event! — goes in through the same in-chan. Either way nothing is kept between events: each starts from the client's signals (a click) or from the machine's initial state (a server event, which brings what it needs as its params).
The use case: process a component's event. It runs as a
`clojure.core.async.flow` of two procs, each in its own namespace:

  in-chan ──▶ :controller ──:to-view──▶ :view ──▶ out-chan
              (state machine)            (render)
              process-event.controller   process-event.view

The messages are described in `process-event.common`. Everything here is
plain data in and out: the caller resolves the component (its machine and
render fn, as vars) and turns a request into a message (adapters); the
rules about the ctx and the transition are the domain's.

Two lifetimes:
- a DEFAULT component's event gets a flow of its own (`process-event`):
  put the event, take the render or time out, stop the flow;
- a CONNECTED component's flow lives as long as its SSE stream
  (`start-flow!`), so a later event — a browser POST or a server
  `send-event!` — goes in through the same in-chan.
Either way nothing is kept between events: each starts from the client's
signals (a click) or from the machine's initial state (a server event,
which brings what it needs as its params).
raw docstring

taia.ds.datastar.use-cases.process-event.common

What travels through a component's flow — the contract the procs (process-event.controller, process-event.view) and the flow's callers share.

IN (on the flow's in-chan, whoever sends it):

{:event [event-name params] ; required :signals {…} ; the component's slice of the client's signals, or nil :request-ctx {:logged-user … :app-config … :request-method …} ; only for an event that came with a request :mulog-ctx ctx ; optional: the sender's trace, re-established :reply promise} ; optional: rides through to the render

Plain data: no Ring request. adapters.handlers.request/->event-msg builds one from a request; server-event builds one for a server event.

BETWEEN the procs and OUT (on the flow's out-chan): {:event :initial-ctx :ctx …} with the same :mulog-ctx and :reply, plus :html once the view has rendered — or an error message when a step threw (error, error-of).

What travels through a component's flow — the contract the procs
(`process-event.controller`, `process-event.view`) and the flow's callers
share.

IN (on the flow's in-chan, whoever sends it):

  {:event       [event-name params]  ; required
   :signals     {…}                  ; the component's slice of the client's signals, or nil
   :request-ctx {:logged-user … :app-config … :request-method …}
                                     ; only for an event that came with a request
   :mulog-ctx   ctx                  ; optional: the sender's trace, re-established
   :reply       promise}             ; optional: rides through to the render

Plain data: no Ring request. `adapters.handlers.request/->event-msg` builds
one from a request; `server-event` builds one for a server event.

BETWEEN the procs and OUT (on the flow's out-chan): {:event :initial-ctx
:ctx …} with the same `:mulog-ctx` and `:reply`, plus `:html` once the view
has rendered — or an error message when a step threw (`error`, `error-of`).
raw docstring

taia.ds.datastar.use-cases.process-event.controller

The :controller proc of a component's flow: the state machine.

It reads events from the flow's in-chan (an in-port), builds the ctx the event transitions from (domain.ctx: from the client's signals, or the machine's initial state for a server event), runs the machine (domain.event) and emits {:event :initial-ctx :ctx} on :to-view. Nothing is kept between events.

The `:controller` proc of a component's flow: the state machine.

It reads events from the flow's in-chan (an in-port), builds the ctx the
event transitions from (`domain.ctx`: from the client's signals, or the
machine's initial state for a server event), runs the machine
(`domain.event`) and emits {:event :initial-ctx :ctx} on `:to-view`.
Nothing is kept between events.
raw docstring

taia.ds.datastar.use-cases.process-event.view

The :view proc of a component's flow: rendering.

It calls the component's render fn with the ctx the controller emitted (:from-controller) and puts the result, as :html (hiccup or an effects list), on the flow's out-chan (the :to-render out-port). An error message from the controller passes through untouched.

The `:view` proc of a component's flow: rendering.

It calls the component's render fn with the ctx the controller emitted
(`:from-controller`) and puts the result, as `:html` (hiccup or an effects
list), on the flow's out-chan (the `:to-render` out-port). An error
message from the controller passes through untouched.
raw docstring

taia.ds.state-machines.domain

Malli schemas for state machine data structures. Available on both JVM and ClojureScript via reader conditionals — Malli requires :clj for fn? predicates, so those are guarded.

Malli schemas for state machine data structures.
Available on both JVM and ClojureScript via reader conditionals —
Malli requires :clj for fn? predicates, so those are guarded.
raw docstring

taia.ds.state-machines.test-helpers

Declarative tests for hierarchical state machines: expectations map, ordered trace of action/invoke labels. Invoke :src is not run; each id uses :invoke-returns if present, else {}. Returns :ok or failure maps for RCF.

Declarative tests for hierarchical state machines: expectations map, ordered trace
of action/invoke labels. Invoke :src is not run; each id uses :invoke-returns if present,
else {}. Returns :ok or failure maps for RCF.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close