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

New patch encoding question #375

Closed jeffa5 closed 3 years ago

jeffa5 commented 3 years ago

Implementing the new patch generation in Rust I've got all of the other tests working but not sure about this one:

https://github.com/automerge/automerge/blob/2cdbe440429eb7d9218961530ea8a486edcaa497/test/backend_test.js#L287-L289

In particular, I'm not entirely sure of what that action (the update) is saying?

From the test it seems that the two maps are in conflict and I suppose in change4 that conflict gets automatically resolved but from the documentation on MapDiff I'm not sure what an empty props signifies: https://github.com/automerge/automerge/blob/2cdbe440429eb7d9218961530ea8a486edcaa497/%40types/automerge/index.d.ts#L249-L253

If no keys are changing do we need to send anything in the patch?

I assume I'm missing something but will be good to clarify and maybe add something to the documentation.

ept commented 3 years ago

Hi @jeffa5, in this test there is a conflict on the list element (two different map objects were assigned to the same list element), and the new patch format represents a conflict by having several consecutive edits with the same index. Moreover, when an update occurs within a conflicted property (in this case, setting the done field in one of the nested maps), the patch reiterates the fact that a conflict is present. This is important so that the frontend can tell the difference between a patch that resolves a conflict and a patch that leaves a conflict unresolved. The empty props object indicates that the object in this branch of the conflict is unchanged.

Does that answer your question?

jeffa5 commented 3 years ago

Ok that makes things clearer. I think I was just missing that you have to keep conflicted objects in the patch (with a potentially empty props or edits) until they are resolved. Thanks!