Collaborative editing
See original GitHub issue@yatskevich and me did a research and tried to design an appropriate architecture for supporting collaborative editing. There are some key points with explanation below.
The main idea is to implement a kind of Redux-like behavior within Slate.
<Editor store={Store} … />
The goal of having Store is ability to have clear separation and understandable flow.
UseCase:
- User press key (types symbol)
- Action is generated
- Action is dispatched to Store
- Store updates State
- setState called
- Editor re-rendered
This way allows us to have ability to manage operations in any suitable way (CRDT, OT, etc.) within Store.
Let’s see how to handle text paste operation in more details:
- Action
pasteText
dispatched to Store (data: {position, text}
) No need to get current state, call transform() and return new state. Just dispatch an Action. - Store has a Reducer for handling such an Action If we’re talking about ColloborativeStore - one type, if about SimpleStore - another one. We can even have few implementation of CollaborativeStores (CRDT and OT).
CollaborativeStore:
- Splits
pasteText
operation into a set of atomicinsertCharacter
operations - Applies operations to State
- Translates this operations set to server
- Listens for updates from server (i.e. smb else is editing this doc and generates the same type of operations set)
SimpleStore:
- Applies operations to State (no need to split to atomic operations)
In our mind such architecture allows Slate to be more flexible and extensible. But this is not a completely analyzed proposal - just an idea.
And a few pictures for clarification.
Workflow Chart:
Implementation example
pastText
in depth:
P.S. Possibly, Store should send Transfroms (not Actions) to Server and get Transforms back.
@ianstormtaylor: Could you please take a look at this and share your opinion?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:29
- Comments:125 (25 by maintainers)
Top GitHub Comments
Created plugin for co-editing: https://github.com/cudr/slate-collaborative
Hope, this will help for someone
Hey all, the OT branch was merged in
0.22.0
so everything that unlocks OT should now be present in Slate’s core! More specifically:Change
objects are available for each change, with the exact operations that occurred.apply
andinvert
operation helpers are exposed.I don’t think Slate’s core will actually add the OT logic itself, since it isn’t used for all use cases and would add bloat. So instead, it would live in another package. If anyone wants to start collaborating on creating that package that would be amazing!
If you’re working on that, and you run into any places that Slate’s core is still missing functionality required, let me know and we can get it fixed. But I’m pretty sure it’s all there.