automerge / automerge-classic

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
http://automerge.org/
MIT License
14.75k stars 466 forks source link

wip: Implement new sequence patch format #327

Closed alexjg closed 3 years ago

alexjg commented 3 years ago

This is a first shot at implementing the new sequence patch format outlined in #311. It's mostly working with the exception of the Observable API. I need to spend some time figuring that out but I wanted to get some eyes on this first.

There is one outstanding question I have which relates to the value of the pred attribute for multiOp delete operations. Consider this operation:

{
  obj: listId, 
  action: 'del', 
  elemId: '1@xxx', 
  multiOp: 2,
  insert: false,
}

In order for this to work we need to specify the predecessor operations for each element being overwritten. The approach I've gone for in this patch is to flatten the predecessor IDs for the whole set of deleted list elements into one pred array and attached it to the op. This works but it feels clumsy and belies the intent of this protocol change - which is to reduce the size of these operations - as we have to include at least one predecessor ID for every deleted element. Is there a better way? Have I misunderstood the use of the pred attribute in the protocol?