joebobmiles / zustand-middleware-yjs

Zustand middleware that enables sharing of state between clients via Yjs.
MIT License
103 stars 10 forks source link

Why not support Y Text shared type? #36

Closed arvinxx closed 1 year ago

arvinxx commented 1 year ago

Hello, this is a great middleware. But I'm curious why not support Y Text shared type?

joebobmiles commented 1 year ago

When I published this package, I needed it to solve the problem of synchronizing structured data, not editable text. That was a while ago, and I had poked around at implementing support for the YText type a few months ago. Life has dragged me away from this project (and its sibling y-react), but now I'm back in a place to resume work. So it would be reasonable to see that support come in the next month or so.

The technical reason why this isn't implemented yet is due to how this middleware 'patches' the local and shared data structures. To properly support YText, I need a fast but accurate text diff algorithm that provides the smallest set of changes to apply in either direction (local to shared or shared to local). Unfortunately, there are not a lot of convenient solutions in the JavaScript ecosystem last I checked, so I have to implement my own version.

arvinxx commented 1 year ago

Thanks for your reply. And how about awareness ? I think awareness is a necessary stuff for collaboration.

joebobmiles commented 1 year ago

I will have to think more about adding awareness. I am hesitant to include it due to the potential performance issues and the possibility of replacing the awareness protocol with a YMap in the Zustand store.

I will have to come back to that after digging into the difference between the awareness protocol and the rest of the Yjs shared types.

In the meantime, if you are using React, I did implement a hook for managing an awareness protocol instance as part of my y-react library. An example can be seen in the project I originally developed this middleware for.