-
Notifications
You must be signed in to change notification settings - Fork 51
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 real time collaboration support #32
Conversation
This makes the timings more realistic
Debounces `input` events without relying solely on the `change` event. The `change` event isn't fired in a consistent manner. The expected behavior is for it to fire only on the trailing edge of the debounce, but sometimes it fires only on the leading edge. When this happens, the change will never be communicated to the handlers until another change happens.
@youknowriad I’m currently doing direct imports of three AsBlocks functions here. Do you think it would make sense to:
|
# Conflicts: # package.json # yarn.lock
@mirka To be honest, I think it's better to just copy/paste the code here. asblocks is an app on its own and not really meant to be "reused" as is. And to avoid future diversions to break anything here, I think it's better to just copy this code here. I also don't think it's too much code. WDYT? |
Yeah, I'd go along with that too. We can see how things develop here and revisit it in the future if it makes sense. |
I'm excited to see the potential for this, and it'll be interesting to think how it could be used in other places. Could you add something to the readme explaining how it might be used? I'm curious as to how peers are found. I am having a few troubles getting it running though. Running
Followed by:
There are also a couple of lint errors when building:
When I tried to use this in an external project (using
|
Sure, that works for me. Thanks!
Yes, I'll add a readme for the transport module interface, it only has basic JSDoc descriptions right now. Short answer is that the code here in iso-editor does not handle peer discovery — it just waits to be notified when peers change. The consumer will have to provide a transport module that talks to their server, whether that be via WebSocket, WebRTC, or even Local Storage, like in the Storybook demo. I addressed the build and lint issues, sorry about that!
|
For an in-depth code review I think a lot of people would be better at that than me, but I did try my very best to break this by playing around with it and I was not successful. It works really well. Great work Lena! |
Co-authored-by: Riad Benguella <[email protected]> Co-authored-by: Enrique Piqueras <[email protected]>
Thanks, it's all working great now! I wasn't able to break anything, either in the storybook, or when the isolated editor is used elsewhere. Everything looks great. A minor thing, and maybe not important, but if there is a background colour the last character from a peer is black: Typing (or randomly mashing the keyboard) does seem a bit slower than a plain editor, but it's possible this is some interaction with the storybook system itself. Would really need to try it in P2 itself. Enabling the block inspector in the storybook would allow further testing, but it's not a blocker. Bundled file sizes do seem to increase quite dramatically. The P2 Editor goes from 84KB to 167KB, for example. This is maybe ok for P2 as we want to use collaboration there, but for the other clients it's a big change. Possibly the code could be exported as a component or a hook ( I don't want to slow things down so I'm ok with this merging as-is, and then looping back to optimize later.
Ah, that makes sense, thanks. |
Thanks for reviewing & testing!
You’re right, that’s about 26KB vs. 51KB gzipped, mainly the size of the Yjs library. Given that most consumers will likely not use the collab feature, I agree we should keep it tree shakeable. I’ll take note of this as a follow-up task. |
Super stuff, a 👍 from me. I can push the changes out to npm when you're ready. |
Proposed changes
useYjs
React hook that adds real time collaborative editing features, powered by the Yjs-based AsBlocks. These features will only kick in when enabled and given a transport module viasettings.collab
.TODO
Punted
Testing instructions
yarn install && yarn storybook
to open a Storybook story for the collaboration-enabled editor.localStorage.debug = 'iso-editor:collab'
.Open two or more browser tabs with this same Storybook page, and see the edits sync across all the clients.