原文
![]() |
|
![]() |
| We built it from scratch, so not based on prosemirror or contenteditable or anything like that (as we needed something which feels as if you're just editing text but also supports outlining features) |
原始链接: https://news.ycombinator.com/item?id=41099901
文本描述了多人任务/注释编辑器的开发,该编辑器结合了文本编辑和大纲功能,尽管看起来很平坦,但在幕后创建了分层文档结构。 它采用“insmov”操作来处理对树所做的更改,允许客户端与服务器无缝同步这些更改。 该系统确保按时间顺序处理更改,而不使用分数索引。 同步问题主要出现在断线期间(例如航空旅行),而不是通过网络套接字实时出现。 此外,作者寻求有关在涉及多个互连树的单用户应用程序中管理复杂状态的指导。 他们提到了确保并发更新不会导致各个浏览器选项卡之间的整体状态不一致的挑战。 他们提出的方法涉及最小化和排队状态更改,但认识到由于过多的数据传输而造成的潜在浪费。 作者发现实现无冲突复制数据类型 (CRDT) 的价值在于简化前端结构中的状态管理,提供选项卡之间的无缝同步并消除自行处理同步的需要。 然而,他们质疑 Yjs 等解决方案所需的开销是否会使其对于本质上不协作或不需要实时功能的应用程序不太可行。
![]() |
|
![]() |
| We built it from scratch, so not based on prosemirror or contenteditable or anything like that (as we needed something which feels as if you're just editing text but also supports outlining features) |
There is one operation to change the tree, called insmov (move-or-insert). Whenever a client is online it can sync changes C to a server. Whenever the server has remote changes for us, it will send us back a list R of all changes since our last sync in a global linear order. We then undo any of the insmovs in our changeset C, and (re)apply all changes in R + any new changes we didn't sync yet.
We don't use any fractional indices though. Instead, our insmov tuple not only contains a parent P, but also a previous sibling guid A. Because all tree ops will eventually be applied in the global linear order as determined by the server, "sorting" is handled by just using the insmov operation.
Most of the time the undo'ing of operations is not needed though. Only when the server has insmov changes we don't know about while we are sending new insmovs ourselves do we need to ensure we replay the operations in the correct order. That's likely to happen when you reconnect to wifi after a long flight, but not so likely when updates are pushed in real-time over websocket when you're online (plus it's not needed for non-insmov operations, like updating text).
[1] https://thymer.com