joebobmiles / zustand-middleware-yjs

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

Rewrite for stability and code cleanliness #2

Closed joebobmiles closed 3 years ago

joebobmiles commented 3 years ago

The code currently in the master branch is a mess, and I barely understand how it works. I know it works since the tests pass, but there is significant room for improvement. This PR will track my progress on the rewrite.

TODO:

joebobmiles commented 3 years ago

There's something wonky going on with patchSharedType that leads to the Zustand store having nested objects and arrays erased. See the results of the failing tests for examples of this.

For those (including future me) who are too lazy to parse the test output, here's what I've been observing:

joebobmiles commented 3 years ago

After a break and some further reflection, it seems not to be a problem isolated solely to patchSharedType. Instead, it seems that it's an interaction between patchSharedType and patchStore when patchStore is invoked inside a map.observeDeep call.

I'd still like to know what interaction is going on that causes the problem I've been observing.

joebobmiles commented 3 years ago

I figured out that the problem was actually inside patchStore. When there were no changes to 'patch' into the old store, an empty array or object would be returned. This caused the truncation I observed. Simply adding a check for when there are no changes circumvented that problem.

joebobmiles commented 3 years ago

:tada: This PR is included in version 1.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: