Implementing the conflict resolution
At this point, PouchDB returns conflicts when they exist and assigns them to the Item
model for use by our controllers and views. The next step is to expose this information to the users and let them resolve conflicts when they arise.
Adding the supporting methods
The last thing that we need to add to the Item
store is a couple of supporting methods. As PouchDB returns a list of conflict revisions but not the data attached to each revision, we need to fetch this explicitly. People need to see what data is attached to each revision in order to select the right one.
Edit the Item
store and add the following method:
getAllConflicts: function(me, store, id, revs, docs, callback) { if (!revs.length) { callback(docs); return; } store.get(id, { rev: revs.shift() }, function(error, doc) { docs.push(doc); me.getAllConflicts(me, store, id, revs, docs, callback); }); },
Normally, we would use allDocs
to return a list of documents, but it only...