folkwaysDocs
JavaScript SDK

Migrating from 0.1

What changed in @folkwaysio/realtime 0.2, and how to update apps written for 0.1.

0.2 makes memory use explicit and bounded. A client no longer keeps history for every topic it has touched: data is kept only while a view of it is open, and every queue has a budget.

In 0.1In 0.2
A topic handle was a long-lived object holding its historyA handle is a lightweight address. Compare handles by name
Messages and values were kept for every topicKept only while a view is open: messages.open(), values().open()
Every publish appeared in the message listOnly while a message view is open. Publishing is otherwise headless
Queues could grow without a set limitPending publishes, inbound work, state, iterators and the cache each have a budget; see Resource management
Signal lifetimes were estimated on the deviceThe service sends each signal's expiry and its clock
Server code called the Realtime API endpoints for members, DMs, kick and revoke directlyRest has members, dm, kick() and revoke(), and createToken() returns jti
The cache defaulted to 5 MiB2 MiB

Update your code

Open a view where you show data, and dispose it when you're done.

TypeScript
const room = client.topic('rooms/42');
const messages = room.messages.open(); // before subscribing, to receive the replay
const stop = messages.subscribe(() => render(messages.getSnapshot()));
const sub = room.subscribe({ from: { last: 50 } });
// later
stop();
messages.dispose();
await sub.unsubscribe();

In React, memoize the view by client, topic and event, and bind it with useSyncExternalStore. Its subscribe opens and releases the view for you:

TypeScript (TSX)
const view = useMemo(() => client.topic(name).messages, [client, name]);
const messages = useSyncExternalStore(view.subscribe, view.getSnapshot);

Handle QueueFull. It now means one of several budgets is full: pending publishes, a topic's inbound work, an iterator's buffer. See Resource management.

Iterators. for await loops have their own bounded buffer each; overflow throws QueueFull for that loop only. Save your own cursor as you process events: the shared cursor tracks callback delivery, not iterator consumption.

Sign-in changes. updateToken() with another identity clears all view data and fails pending sends; views stay open. Subscribe again once it resolves.

Server. Replace calls to the members, DM, kick and revoke endpoints with folkways.members, folkways.dm, folkways.kick() and folkways.revoke(). See Issue tokens from your backend.

Before you ship

Test mounting and unmounting screens, headless publishers, slow consumers, large snapshots, reconnects, sign-out and persistent storage with your real data sizes.

On this page