Skip to content

Commit

Permalink
Remove resolve method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Nov 20, 2021
1 parent 22b368b commit 195b3f0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 70 deletions.
5 changes: 0 additions & 5 deletions docs/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ Finally, there may be occasions when "first write wins" would be more appropriat

Other options exist that might refine our merging strategy, such as [CRDT's](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type), but so far such an approach has yet to be implemented.

# Resolving conflicts
When a conflict does occur, it can be detected as a non-zero length on the `conflicts` array. Note, too, that `merge` operations will not be permitted on entities that have any outstanding conflicts, although `update` operations will be allowed.

To resolve a conflict, you can use the `farm.meta.resolve` method, which takes the entity with the conflict, the field you wish to resolve, and a callback, which receives an array of all the conflicts for that field, and must return the index of the conflict to select, or `-1` if the local value is to be preserved.

# Sync status
The `farm.isUnsynced` method is a quick way of determining whether or not an entity has been synced to a remote system:

Expand Down
19 changes: 0 additions & 19 deletions src/model/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import clone from 'ramda/src/clone.js';
import map from 'ramda/src/map.js';
import partition from 'ramda/src/partition.js';
import createEntity from './create.js';
import mergeEntity from './merge.js';
import updateEntity from './update.js';
Expand Down Expand Up @@ -68,24 +67,6 @@ export default function model(opts = {}) {
on: addListeners('schema'),
},
meta: {
resolve(entity, field, cb) {
const copy = clone(entity);
const byField = c => c.field === field;
const [conflicts, others] = partition(byField, copy.meta.conflicts);
const index = cb(conflicts);
if (typeof index !== 'number') return copy;
if (index > -1 && index < conflicts.length) {
const { changed, data, fieldType } = conflicts[index];
copy[fieldType][field] = data;
copy.meta.fieldChanges[field] = changed;
copy.meta.conflicts = others;
if (changed > copy.meta.changed) copy.meta.changed = changed;
}
if (index === -1) {
copy.meta.conflicts = others;
}
return copy;
},
isUnsynced(entity) {
const { changed, remote: { lastSync } } = entity.meta;
return lastSync === null || changed > lastSync;
Expand Down
46 changes: 0 additions & 46 deletions test/model/resolve.js

This file was deleted.

0 comments on commit 195b3f0

Please sign in to comment.