You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,7 +13,7 @@ Primitives for [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web
13
13
-[`makeSSE`](#makesse) — Base non-reactive primitive. Creates an `EventSource` and returns a cleanup function. No Solid lifecycle.
14
14
-[`createSSE`](#createsse) — Reactive primitive. Accepts a reactive URL, integrates with Solid's owner lifecycle, and returns signals for `data`, `error`, and `readyState`.
15
15
-[`makeSSEWorker`](./WORKERS.md) — Runs the SSE connection inside a Web Worker or SharedWorker. See [WORKERS.md](./WORKERS.md).
`EventSource` has native browser-level reconnection built in. For transient network drops the browser automatically retries. The `reconnect` option in `createSSE` is for _application-level_ reconnection — it fires only when `readyState` becomes `SSEReadyState.CLOSED`, meaning the browser has given up entirely. You generally do not need `reconnect: true` for normal usage.
156
156
157
-
## Built-in transformers
158
-
159
-
Ready-made `transform` functions for the most common SSE data formats. See [TRANSFORMS.md](./TRANSFORMS.md) for full documentation and examples.
Parse the message data as [newline-delimited JSON](https://ndjson.org/) (NDJSON / JSON Lines). Each non-empty line is parsed as a separate JSON value and the transformer returns an array.
254
+
255
+
Use this when the server batches multiple objects into one SSE event:
Split the message data into individual lines, returning a `string[]`. Empty lines are filtered out. Useful for multi-line text events that are not JSON.
const { data } =createSSE<string[]>(url, { transform: lines });
278
+
// data() === ["line one", "line two"]
279
+
```
280
+
281
+
### `number`
282
+
283
+
Parse the message data as a number using `Number()` semantics. Handy for streams that emit counters, progress percentages, sensor readings, or prices.
284
+
285
+
```ts
286
+
import { createSSE, number } from"@solid-primitives/sse";
287
+
288
+
const { data } =createSSE<number>(url, { transform: number });
289
+
// data() === 42
290
+
```
291
+
292
+
Note: follows `Number()` coercion — an empty string becomes `0` and non-numeric strings become `NaN`.
293
+
294
+
### `safe(transform, fallback?)`
295
+
296
+
Wraps any transform in a `try/catch`. When the inner transform throws, `safe` returns `fallback` instead of propagating the error. This keeps the stream alive across malformed events.
// Returns undefined on a bad event instead of throwing
302
+
const { data } =createSSE<MyEvent>(url, { transform: safe(json) });
303
+
304
+
// With an explicit fallback value
305
+
const { data } =createSSE<number>(url, { transform: safe(number, 0) });
306
+
```
307
+
308
+
### `pipe(a, b)`
309
+
310
+
Composes two transforms into one: the output of `a` is passed as the input of `b`. Useful for building custom transforms from existing primitives without writing anonymous functions.
0 commit comments