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

YWeakLink #581

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

YWeakLink #581

wants to merge 4 commits into from

Conversation

Horusiath
Copy link

@Horusiath Horusiath commented Oct 6, 2023

Based on our previous PoC, this is a general draft for YWeakLink data type. Its API is similar to JavaScript WeakRef. Yrs has a companion version of this feature.

  1. You can create links to map and array elements via ymap.link('key')/yarray.quote(index, length)/ytext.quote(index, length). I didn't make it for XML elements, as it doesn't have any sense: XML is acyclic tree-like structure by definition. You can make links referencing to fragments of YText type, and you can embed them as AbstractTypes inside YText.
  2. Underlying link values can be retrieved via ylink.deref() method just like in JavaScript WeakRef. If linked value has been deleted, undefined will be returned. For text and arrays this method will return first element from the quoted range. You can also call link.isSingle() to check if current weak link refers to single element or range of elements.
  3. For YArrap, quoted ranges can be retrieved using ylink.unquote(): it will return a list of elements within a quoted range.
  4. For YText/YXmlText it's possible to get plain/xml-fromatted string using ylink.toString() and get delta using ylink.toDelta().
  5. Links can point to scalar values or other shared y-types.
  6. Deleting link WON'T delete linked value.
  7. Links can be observed on. Map link changes are automatically propagated as key is being updated or deleted. Array links changes react on deletes, but inserting new value at the same index DOESN'T count as updating the link's value.
  8. Links can be used in combination with deep observe calls. This way changes in y-types are propagated not only up in their parent hierarchy, but also spread out across their links (and further up to link's parents). If such hierarchy creates cycles, they will be caught and prevent from making stack overflow.

PS: I'm planning to make a demo to provide more pracitcal context for this feature.
PSS: There also a need to change some of the iteration algorithm once the move branch is to be merged into main.

@Horusiath Horusiath marked this pull request as ready for review November 9, 2023 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant