v4.3
We're excited to announce TinyBase 4.3, which provides an integration with PartyKit, a cloud-based collaboration provider. Read the release blog post here.
This integration allows you to enjoy the benefits of both a "local-first" architecture and a "sharing-first" platform. You can have structured data on the client with fast, reactive user experiences, but also benefit from cloud-based persistence and room-based collaboration.
This release includes two new modules:
-
The persister-partykit-server module provides a server class for coordinating clients and persisting Store data to the PartyKit cloud.
-
The persister-partykit-client module provides the API to create connections to the server and a binding to your Store.
A TinyBase server implementation on PartyKit can be as simple as this:
import {TinyBasePartyKitServer}
from 'tinybase/persisters/persister-partykit-server';
export default class extends TinyBasePartyKitServer {}On the client, use the familiar Persister API, passing in a reference to a PartyKit socket object that's been configured to connect to your server deployment and named room:
const persister = createPartyKitPersister(
store,
new PartySocket({
host: 'project-name.my-account.partykit.dev',
room: 'my-partykit-room',
}),
);
await persister.startAutoSave();
await persister.startAutoLoad();The load method and (gracefully failing) save method on this Persister use HTTPS to get or set full copies of the Store to the cloud. However, the auto-save and auto-load modes use a websocket to transmit subsequent incremental changes in either direction, making for performant sharing of state between clients.
See and try out this new collaboration functionality in the Todo App v6 (collaboration) demo. This also emphasizes the few changes that need to be made to an existing app to make it instantly collaborative.
Also try out the tinybase-ts-react-partykit template that gets you up and running with a PartyKit-enabled TinyBase app extremely quickly.
PartyKit supports retries for clients that go offline, and so the disconnected user experience is solid, out of the box. Learn more about configuring this behavior here.
Note, however, that this release is not yet a full CRDT implementation: there is no clock synchronization and it is more 'every write wins' than 'last write wins'. However, since the transmitted updates are at single cell (or value) granularity, conflicts are minimized. More resilient replication is planned as this integration matures.
