-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating Y.Doc
server-side
#867
Comments
can you try this: import {unstable_getYDoc} from 'y-partykit';
// ...
const doc = await unstable_getYDoc(documentId, options) Make sure that |
What is If I provide The types indicates that it should be of type
As I'm not accessing I also tried accessing the document inside
|
Oh hmm you're right. Thinking about this. Because of how Durable Objects work, the "id" isn't available in alarmsm which you'd need to reference the document. A workaround would be to use room.storage to store the name, but we haven't made that simple so far. Can you tell your usecase? |
Specifically, what is it that you're updating in the document that should happen in an alarm? |
An example—I'm using PartyKit to make a realtime bus tracker app. Every few seconds I need to poll a server to fetch the latest tracking info. I do this on the server so there's a central authority for that data, and because sometimes these requests need API tokens or server-specific modules. Today, I do this without Yjs by sending plain messages to my clients with the latest data. This means I am responsible for keeping state synchronized across server and clients. I would prefer if I could simply write the data to a document on the server, and have clients magically see the latest data when they read the document. This can even be made reactive with a binding like zustand-middleware-yjs. It's not just for alarms either, sometimes I want a message as the trigger. And example of this is https://hmd.link which uses Firebase as the shared document. Clients submit links to server, server fetches OpenGraph data and writes to the document, client UI magically updates. With PartyKit + Yjs I should be able to achieve that without Firebase. |
Turning this into an Issue per discussion on Discord.
The y-partykit docs explain how to sync edits to a client-side Y.Doc via the YPartyKitProvider.
https://docs.partykit.io/reference/y-partykit-api/
I am looking for a way to get a handle on this document to make changes on the server. Currently, the server-side interface for the document is through
load()
andcallback.handler()
which are invoked for the purpose of syncing the document to external storage, rather than a persistent handle that syncs with clients.For example, I may want to update a value when an alarm rings and have that propagate to clients.
The text was updated successfully, but these errors were encountered: