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

Add peer selection display example #544

Merged
merged 4 commits into from
Jun 16, 2023
Merged

Conversation

easylogic
Copy link
Contributor

@easylogic easylogic commented Jun 13, 2023

What this PR does / why we need it?

Allows selection information from the yorkie.Tree to be sent remotely.
support remote selection viewer.

Any background context you want to provide?

Tree selection information is provided by the createRange () function.

const selection = root.tree.createRange(fromIndex, toIndex);

The selection is converted to a string for transmission to the remote.

root.tree.createRange(from, to).map((it) => {
      return yorkie.converter.toHexString(
            yorkie.converter.objectToBytes(
              yorkie.Primitive.of(it.offset, it.createdAt),
            ),
     );
});

As you can see in the code, there is no way to simply send pos, so we wrap it in Primitive.of.
The reason for this is so that we can transform it into bytes and send it.

The converted selection information is then sent via root.selection to root.tree in the same way as root.tree.

root.selection = root.tree.createRange().map( () => {
    .....
});

There's a problem: the selection information is an array, which generates quite a few operations.

Set, Add, Add

At least three things must be done, because range information has from and to.

2023-06-14.5.17.30.mov

What are the relevant tickets?

Fixes #543

Checklist

  • Added relevant tests or not required
  • Didn't break anything

@codecov
Copy link

codecov bot commented Jun 14, 2023

Codecov Report

Merging #544 (63ed1c6) into main (9f6e51b) will decrease coverage by 0.25%.
The diff coverage is 46.87%.

@@            Coverage Diff             @@
##             main     #544      +/-   ##
==========================================
- Coverage   87.99%   87.75%   -0.25%     
==========================================
  Files          77       77              
  Lines        7372     7464      +92     
  Branches      712      731      +19     
==========================================
+ Hits         6487     6550      +63     
- Misses        612      630      +18     
- Partials      273      284      +11     
Impacted Files Coverage Δ
src/api/converter.ts 91.04% <0.00%> (-0.99%) ⬇️
src/document/json/tree.ts 54.44% <0.00%> (-6.05%) ⬇️
src/yorkie.ts 100.00% <ø> (ø)
src/document/crdt/tree.ts 82.95% <50.00%> (-1.17%) ⬇️
test/unit/document/crdt/tree_test.ts 74.20% <100.00%> (+1.02%) ⬆️

... and 5 files with indirect coverage changes

@easylogic easylogic marked this pull request as ready for review June 14, 2023 08:18
@hackerwins hackerwins force-pushed the feat/tree-selection-presence branch 2 times, most recently from edb4ddf to 5fdd8fb Compare June 16, 2023 08:01
@hackerwins hackerwins force-pushed the feat/tree-selection-presence branch from 5fdd8fb to 63ed1c6 Compare June 16, 2023 08:09
@hackerwins hackerwins self-requested a review June 16, 2023 08:33
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

@hackerwins hackerwins merged commit c501c03 into main Jun 16, 2023
2 checks passed
@hackerwins hackerwins deleted the feat/tree-selection-presence branch June 16, 2023 08:50
@hackerwins hackerwins changed the title Implement to make tree selection info Add peer selection display example Jun 16, 2023
hunkim98 pushed a commit to hunkim98/yorkie-js-sdk that referenced this pull request Jul 12, 2023
Co-authored-by: Youngteac Hong <susukang98@gmail.com>
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.

Implements Tree.createRange, Tree.RangeToIndex, Tree.rangeToPath
2 participants