The core SDK mainly provides tools for working with SSE-gens in a generic manner. To do so all specific SSE-Gens are implementations of the starfederation.datastar.clojure.protocols/SSEGenerator protocol. This way you use the same namespace regardless of the specific adapter you are using.
This is the main entry point for using the SDK.
Building on the patching functions we have convenience functions to send JavaScript scripts to the browser to execute:
There are also some simple utilities for generation Datastar actions to put in HTML:
This namespace contains code shared between specific adapters. This is a more Advanced API needed mostly if you start writing custom adapters or custom write profiles.
It contains:
->sse-response
functionsThis namespace contains a few mock SSEGenerator implementations.
We try to provide a similar model for working with SSE in each adapter we support by sticking as close as possible to the ring spec.
When using the SDK you will mainly use a ->sse-response
function. It returns a
ring response map that starts a SSE stream and is tailored to the adapter you
are using.
The response map will contain a response status, the required SSE headers and a body.
important
You can modify the response map except for the body and the SSE headers.
For every adapter this function takes 2 arguments:
You get access to the SSE-Gen as an argument to the callbacks yo pass to
->sse-response
.
The SSE connection is open and ready when the on-open
callback is run.
If you don't plan on keeping it open you must close it yourself here.
When the adapter detects the client disconnecting or when you close the
SSE-Gen yourself the on-close
callback will be called. Note that when that
happens it is already no longer possible to send events.
When sending events to the client, if an exception is thrown a on-exception
callback will be called. If you don't provide it a default one will be used.
The default behavior is to close the connection on java.io.IOException
and
rethrow otherwise.
We have tried to keep the differences between the adapters minimal. Still not all ring adapters use the same mechanism to represent SSE streams and some differences are unavoidable.
These differences revolve mainly around disconnect detection and how the ring synchronous and asynchronous APIs behave.
Refer to the SDK adapter READMEs for more information.
Besides the ->sse-reponse
function the starfederation.datastar.clojure.adapter.XXX
namespaces provides aliases to the commonly used code from the
starfederation.datastar.clojure.adapter.common
namespace.
Can you improve this documentation?Edit on GitHub
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 |