resolve method
Future<DatumConflictResolution<T> >
resolve({
- T? local,
- T? remote,
- required DatumConflictContext context,
override
Resolves a conflict between a local and remote version of an entity.
Implementation
@override
Future<DatumConflictResolution<T>> resolve({
T? local,
T? remote,
required DatumConflictContext context,
}) async {
if (local == null && remote == null) {
return DatumConflictResolution.abort(
'No entities supplied to CRDT resolver.',
);
}
// A deletion conflict has no second state to merge with — preserve the
// content that still exists so the document cannot be lost, and let the
// engine converge the other side.
if (remote == null) {
return DatumConflictResolution.useLocal(local as T);
}
if (local == null) {
return DatumConflictResolution.useRemote(remote);
}
final merged = local.merge(remote) as T;
// `DatumEntityMixin.merge` defaults to `=> other`. If the "merge" is
// literally the remote instance while the two sides differ, the entity
// almost certainly never implemented CRDT merging — surface it instead
// of silently discarding the local edits.
if (identical(merged, remote) && local != remote) {
return DatumConflictResolution.merge(
merged,
message: 'Entity ${context.entityId} resolved with the DEFAULT merge (=> other): '
'the entity type does not override merge(), so CRDTResolver degraded '
'to take-remote and any concurrent local edits were discarded. '
'Override merge() to combine CRDT fields.',
);
}
return DatumConflictResolution.merge(merged);
}