Skip to content
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 29 commits into from
Mar 14, 2023
Merged

feat: text support #40

merged 29 commits into from
Mar 14, 2023

Conversation

joebobmiles
Copy link
Owner

@joebobmiles joebobmiles commented Mar 10, 2023

Creating this since I'm almost done with implementing support for conflict-free text via Yjs YText. Only have a few things left:

  • State mapping needs to map between strings and YText objects.
    • Write tests to confirm mapping is correct.
    • Implement string ⇒ YText mapping.
    • Implement YText ⇒ string mapping.
  • Write integration tests
    • How to check that we are actually using YText and not strings?
      • The best way to confirm that we are using YText is to induce a race condition (two users typing at the same time) and look for behavior that indicates we are using strings. YText conflict resolution is non-deterministic, so we can't perform a check for that. But I think string replacement is deterministic, so we should be able to check that.

Will be using this to post updates instead of #39.

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 joebobmiles merged commit f571511 into staging Mar 14, 2023
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))
@joebobmiles
Copy link
Owner Author

🎉 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))
@joebobmiles
Copy link
Owner Author

🎉 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant