merge method

CRDTRecord merge(
  1. CRDTRecord other
)

Implementation

CRDTRecord merge(CRDTRecord other) {
  if (clock.dominates(other.clock)) {
    return this;
  }

  if (other.clock.dominates(clock)) {
    return other;
  }

  // concurrent updates → deterministic merge
  final mergedData = {...data, ...other.data};

  final mergedClock = VectorClock({
    ...clock.versions,
    ...other.clock.versions,
  });

  return CRDTRecord(
    id: id,
    data: mergedData,
    clock: mergedClock,
    tombstone: tombstone || other.tombstone,
  );
}