PouchDB Resolve Conflicts
PouchDB plugin to assist in PouchDB conflict resolving.
Disclaimer
Conflict resolution should better be done server side to avoid hard to debug loops when multiple clients resolves conflicts on the same documents.
Installation
pouch-resolve-conflicts is hosted on npm.
Node
Install via npm install pouch-resolve-conflicts
var PouchDB = PouchDB
Browser
Use the browserified build.
Usage
// The resolve function. This function takes two documents and returns either// one of them, a changed version of one of them, or nothing. In the latter the// conflict will not be resolved. If there are more than two conflicting// versions this function will be called with each version against the former// result. { // cannot merge: return nothing if 'foo' in a && 'foo' in b return // return one of the docs if 'foo' in a return a if 'foo' in b return b // return changed doc afoo = 'bar' return a} var db = 'mydb' db // Lets have a conflict // Query doc with `conflicts: true` // And resolve it // `resolveFun` can also return a promise: { return { if 'foo' in a && 'foo' in b return if 'foo' in a return if 'foo' in b return afoo = 'bar' return }}
Tests
npm test