Streaming

Streaming

RAF-batch async sources into an explicit Pretable row model.

@pretable/stream-adapter connects an async source to an explicit row model. It coalesces producer events into at most one atomic row-model transaction per animation frame, no matter how fast the source emits.

There are two source shapes, and they behave nothing alike. An element stream appends a whole new row per event; a partial stream patches one fixed row ID over and over. A partial stream adds a row only if you hand it a createRow factory, and never more than the one row it targets. Watch both:

New rows arrive

Each yielded value is a complete row. connectElementStream appends one as it arrives — this grid starts empty and fills in:

Streaming chat grid

Turn a streaming LLM response into rows with connectElementStream and append them to the grid as they arrive.

.md

One row grows

Each yielded value is a Partial<TRow> patch to a single, fixed row ID. Row msg-1 below is seeded before its stream connects; msg-2 isn't seeded, so its first partial is reported through onIssue and createRow builds the row from it:

Partial row stream

Grow one row's content cell in place with connectPartialStream, covering both the seeded-row and createRow/onIssue patterns.

.md

Own the row model explicitly

Both grids above create their own rowModel and pass it to PretableSurface via model, not rows:

ts
import { createLocalRowModel } from "@pretable/core";
 
const rowModel = createLocalRowModel({ rows: [], columns });

For ordinary React data, the declarative rows prop is enough — the surface owns diffing for you. Reach for explicit row-model ownership, as both grids above do, when a high-frequency producer needs to publish transactions directly.

Pick the connector

Each element is a complete new row — the shape behind the grid above.

ts
import { connectElementStream } from "@pretable/stream-adapter";
 
const connection = connectElementStream(rowModel, rows);
await connection.done;

dispose() stops consumption; done resolves on completion/disposal and rejects with source or model failures.

Next