Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict Management Dream API #87

Open
gr2m opened this issue Dec 2, 2015 · 0 comments
Open

Conflict Management Dream API #87

gr2m opened this issue Dec 2, 2015 · 0 comments

Comments

@gr2m
Copy link
Member

gr2m commented Dec 2, 2015

follow up for https://github.com/hoodiehq/wip-hoodie-store-on-pouchdb/issues/32 (make sure to check the discussion, lots of great thoughts in there!)

I see two ways to handle conflicts:

  1. Conflicts can be automatically merged with app-specific logic
  2. Show custom UI to have the user handle conflicts manually

Dream API

I'll keep that updated based on the discussion in this issue.

// all objects returned by all hoodie.store methods and passed
// to all events (change, add, update, remove) have a _conflicts property.

// To find all objects having a conflict, use hoodie.store.findAll with a filter function
hoodie.store.findAll(function(object) {
  return object._conflicts !== undefined;
})
.then(function(objectsWithConflicts) {
  objectsWithConflicts.forEach(function(object) {
    object._conflicts // array of conflicting versions
  })
})

// To resolve a conflict, the hoodie.store update methods accept a `removeConflicts` option.
hoodie.store.update(winningObjectVersion, {removeConflicts: true})
.then(function(newObjectVersion) {
  newObjectVersion._conflicts // undefined
});

// It can also be an array of the conflicting rev IDs or entire object
hoodie.store.update(object, {removeConflicts: [losingVersion1, losingVersion2]})

// Removing an object always automatically removes all conflicting revisions
hoodie.store.remove(object)

// You can listen to conflicts happening in the background
hoodie.store.on('change', function(object) {
  if (object._conflicts) {
    // update UI and/or handle conflict
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant