Implementing conflict detection
PouchDB is aware of conflicts under the hood. By default, when a conflict occurs, it chooses an arbitrary winner and returns it on request. This isn't quite the behavior that we want. Instead, when a conflict occurs, we want PouchDB to give us a list of all of the conflicts so that the user can resolve them. The first step is altering our stores to detect and expose the conflicts.
Getting PouchDB to return conflicts
The first step is to get PouchDB to return a list of the conflict revisions. Edit the doWithDocs
method in the Item
store and add the following option to the allDocs
method immediately after the endKey
option:
conflicts: true
Now, each document with conflicts will have a _conflicts
attribute with an array of all the losing conflicts. Once we have this, we can let the user select the revision that they actually want to win and then remove all of the other conflicts.
Attaching conflicts to the item model
Now that PouchDB is returning conflicts, we need...