Skip to content
This repository has been archived by the owner. It is now read-only.

[Question] How to boostrap slate with a persisted doc? #80

Closed
mdegrees opened this issue May 3, 2021 · 4 comments
Closed

[Question] How to boostrap slate with a persisted doc? #80

mdegrees opened this issue May 3, 2021 · 4 comments

Comments

@mdegrees
Copy link

mdegrees commented May 3, 2021

First of all, thank you for sharing this awesome piece of work. I managed to run the example just fine. I am trying to get it to work with persisted docs. For now, just for the sake of prototyping, I'm using y-leveldb with y-websocket.

What I can't get my head around is how to bootstrap Slate with the persisted doc. It says here

// Super hacky way to provide a initial value from the client, if
that the initial state should probably come from the server.

If I've well understood, by the time the sync process is done. The client Ydoc is in complete sync with the Websocket copy. No need to fetch anything from the server. Theoretically, I should reflect the Ydoc state on Slate but I can't get it to work. Is this even the right approach? Can you point me please to any working example?

Thank you 🙏

@BitPhinix
Copy link
Owner

BitPhinix commented May 3, 2021

Hi @mdegrees,

Thanks so much for those kind words 😊. To provide an initial value from the server you need to modify the y-websocket code a bit. The initial version of this repo had such an implementation you can use for inspiration:

const content = this.loadDocument(docName);

Sorry in advance for the quality of code in there 😅

@mdegrees
Copy link
Author

mdegrees commented May 3, 2021

@BitPhinix thank you so much for your fast response 🙏 . Looking at the implementation, it does make perfect sense.
toSlateDoc is now toSharedType right?

I think one way to go about it, without implementing a custom server is to use the exposed setPersistence method. As mentioned here yjs/yjs-demos#8 (comment) and here yjs/yjs#170 (comment)

Do you see any value in keeping Yjs' binary version of the doc alongside slate's value?

@mdegrees mdegrees closed this as completed May 3, 2021
@BitPhinix
Copy link
Owner

Hi @mdegrees,

I think one way to go about it, without implementing a custom server is to use the exposed setPersistence method. As mentioned here yjs/yjs-demos#8 (comment) and here yjs/yjs#170 (comment)

If it works it's definitely the way to go, the custom WebSocket server implementation was just a hack to get things running quickly for this repo. We were slate-yjs with a custom go service to handle doc changes in prod.

Do you see any value in keeping Yjs' binary version of the doc alongside slate's value?

Yes, definitely. If you want to allow clients to perform offline modifications you'll need the binary yjs document to be able to merge the changes. With a single service instance this is relatively easy but scaling it across multiple services comes with a lot of challenges. I really recommend https://discuss.yjs.dev. There are a lot of really smart and helpful people in there that can help you along the way :)

@mdegrees
Copy link
Author

mdegrees commented May 4, 2021

Oh cool, I see. Thank you so much for the pointers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants