-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: text support #40
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This uses the algorithm published by Sun Wu, et al. circa 1989 as an improvement on the original Meyers algorithm.
Had an issue where insertions at the head of an array would not be handled properly. Resulting change lists were too long for what was a simple insertion.
Anything more complicated than a number in an array needs to be inspected for changes to its contents. Added a test that confirmed that nested change lists were generated for array elements that needed them.
The diff algorithm from Wu et al. assumes that the two strings being diff'd have at least one common subsequence. If they do not, the algorithm fails, as the outcome is nondeterministic. To avoid this, I added logic that detects if there are no common subsequences and generates an arbitrary edit list that performs the correct transformation.
While its useful to properly identify the type of diffable value we are working with, it is also handy to know when a random value we have is diffable. This helper prevents me from writing long conditions in if statements checking if something is a string, an object, or an array.
For our purposes, if a function is deleted from an object, we want to ignore that. This is due to functions not being serializable and never entering into the Yjs shared types. Because of this, every update coming from Yjs to Zustand will be missing functions, which the change list will tell us to delete if we don't ignore them.
Last thing we needed to test was that we were converting strings to YText objects whenever we went to patch shared types.
Also updated presence caveat with a reference to y-react.
joebobmiles
pushed a commit
that referenced
this pull request
Mar 14, 2023
# [1.3.0-rc.1](v1.2.8...v1.3.0-rc.1) (2023-03-14) ### Bug Fixes * added string diff to getChanges ([82f156a](82f156a)) * array diffs handle insert at head ([530596c](530596c)) * avoid strings with no common subsequences ([4782766](4782766)) * diff ignores functions in objects on deletion ([9a287de](9a287de)) * diff indices not being offset after adds ([b4d3d9b](b4d3d9b)) * diff now handles complicated change sequences properly ([baa3c01](baa3c01)) * refactored patchStore to use new getChanges ([bef2732](bef2732)) * removed excess logic for when a or b are empty strings ([31d93d0](31d93d0)) * simplified object and array diff with helper ([5e4a5f4](5e4a5f4)) * tested string to YText conversion ([8f60467](8f60467)) ### Features * added string patching for store ([0c0ffe1](0c0ffe1)) * added string to YText mapping ([d65f5a0](d65f5a0)) * added YText patching ([d21b785](d21b785)) * array diff now nests string diffs ([7f85523](7f85523)) * implemented base text diff algorithm ([2e833bf](2e833bf)) * object diff now handles string values ([459b88f](459b88f)) * text support [#40](#40) ([f571511](f571511)) * updated basic diff algorithm to produce change lists ([df45cfb](df45cfb))
🎉 This PR is included in version 1.3.0-rc.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
joebobmiles
pushed a commit
that referenced
this pull request
Jun 2, 2023
# [1.3.0](v1.2.8...v1.3.0) (2023-06-02) ### Bug Fixes * added jsdom for jest ([ad84bec](ad84bec)) * added string diff to getChanges ([82f156a](82f156a)) * array diffs handle insert at head ([530596c](530596c)) * avoid strings with no common subsequences ([4782766](4782766)) * clone old state to avoid pass by reference ([30593fb](30593fb)) * diff ignores functions in objects on deletion ([9a287de](9a287de)) * diff indices not being offset after adds ([b4d3d9b](b4d3d9b)) * diff now handles complicated change sequences properly ([baa3c01](baa3c01)) * downgraded typescript and added @types/jest ([fa5e548](fa5e548)) * refactored patchStore to use new getChanges ([bef2732](bef2732)) * removed excess logic for when a or b are empty strings ([31d93d0](31d93d0)) * simplified object and array diff with helper ([5e4a5f4](5e4a5f4)) * tested string to YText conversion ([8f60467](8f60467)) ### Features * added string patching for store ([0c0ffe1](0c0ffe1)) * added string to YText mapping ([d65f5a0](d65f5a0)) * added YText patching ([d21b785](d21b785)) * array diff now nests string diffs ([7f85523](7f85523)) * implemented base text diff algorithm ([2e833bf](2e833bf)) * object diff now handles string values ([459b88f](459b88f)) * text support [#40](#40) ([f571511](f571511)) * updated basic diff algorithm to produce change lists ([df45cfb](df45cfb))
🎉 This PR is included in version 1.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Creating this since I'm almost done with implementing support for conflict-free text via Yjs YText. Only have a few things left:
Will be using this to post updates instead of #39.