joebobmiles / zustand-middleware-yjs

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

is there any update with YJS Text? #39

Closed arvinxx closed 1 year ago

joebobmiles commented 1 year ago

Oh boy. It's been a few months, huh?

So, here are the updates:

  1. I implemented a text diff algorithm that works quite well.
  2. I had trouble integrating the text diff algorithm into the state patching, so I began a refactor.
    • [x] State diffs needed to output a single format instead of the three formats I had implemented (one for arrays, one for objects, and now one for text).
    • [x] State patching needs to handle this new format.
    • [x] State mapping needs to map between strings and YText objects.
      • [x] Write tests to confirm mapping is correct.
      • [x] Implement string ⇒ YText mapping.
      • [x] Implement YText ⇒ string mapping.
    • [ ] Write integration tests
  3. Life happened again, and now we're here four months after I started the refactor.
    • My last commit was Nov 17, 2022.

The good news is that I left off in an easy place to pick up: the refactored array diff algorithm is failing some tests. Specifically tests about detecting insertions at the beginning of arrays.

Question for you: how soon do you need this feature?

arvinxx commented 1 year ago

how soon do you need this feature?

I don't need this feature recently, but later this year. So you can take your time to work on this new feature~ And I am really excited with this.

Beside, when I integrate this in to my application,I found some edge case that throw undefined or null error. I will dig it out and open a new issue soon.

arvinxx commented 1 year ago

FYI: I also find a zustand middleware on https://liveblocks.io/ ,which is RealTimeCollab as a service company. their zustand middleware seems to have more powerful features. Maybe you can infer to them in some way ?

joebobmiles commented 1 year ago

their zustand middleware seems to have more powerful features.

After reading their documentation, the answer is yes and no. Seems that most of the powerful features you see are actually just LiveBlocks features. Some can be replicated in Yjs, for instance, undo-redo and presence, but things like join-leave commands aren't possible without some hacks.

I do like the middleware API. I had originally shied away from configuration objects to "idiot-proof" the middleware, but it could be useful. One thing that irks me a bit about the LiveBlocks middleware is that it injects an API object into the store. I had avoided that because I didn't like the idea of putting middleware-specific data into the store. In hindsight, it's not all that bad, but at the same time, Yjs doesn't have nearly as nice an API as LiveBlocks, so I'm not even sure I could justify having such an object.

joebobmiles commented 1 year ago

Closing this so that I can keep posting updates in #40.

arvinxx commented 1 year ago

Seems that most of the powerful features you see are actually just LiveBlocks features.

Actually I like their core concept like room, presence ,and it combine with zustand middleware very well. for example, I think get awareness information from a object injected by middleware is easier to use.

I had avoided that because I didn't like the idea of putting middleware-specific data into the store. In hindsight, it's not all that bad

I think so, beside liveblock middleware, there is some other middleware just work with the same idea , for example ,zundo. So maybe you can give it a try to add more features like redo、undo within the injected object.

joebobmiles commented 1 year ago

YText is now available in version 1.3.0-rc.1 or install zustand-middleware-yjs@latest. Let me know if you run into any issues.