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

ChangeOptions.time not work ? #379

Closed DiamondYuan closed 3 years ago

DiamondYuan commented 3 years ago
const automerge = require("automerge");

const state = automerge.from({ name: "1" });

const stateOne = automerge.change(
  automerge.load(automerge.save(state)),
  { time: 100 },
  (e) => (e.name = "2")
);

const stateTwo = automerge.change(
  automerge.load(automerge.save(state)),
  { time: 101 },
  (e) => (e.name = "3")
);

console.log(automerge.merge(stateOne, stateTwo));

the result is 2 or 3.

Is the time of change useless?

ept commented 3 years ago

@DiamondYuan The time of change is there purely for your information if you inspect the change history (so that you can see who changed what, when). The timestamp has absolutely no effect on the conflict resolution. In your example, the conflicts are resolved based on the actorIds of the two documents after loading them, which are random UUIDs, so the merged outcome will be either 2 or 3 depending on which UUID ended up being greater.