keep simplifying
diff --git a/packages/node_modules/pouchdb-adapter-utils/src/processDocs.js b/packages/node_modules/pouchdb-adapter-utils/src/processDocs.js index 3350e0a..ed20124 100644 --- a/packages/node_modules/pouchdb-adapter-utils/src/processDocs.js +++ b/packages/node_modules/pouchdb-adapter-utils/src/processDocs.js
@@ -6,7 +6,6 @@ merge, winningRev as calculateWinningRev } from 'pouchdb-merge'; -import { Map } from 'pouchdb-collections'; function rootIsMissing(docInfo) { return docInfo.metadata.rev_tree[0].ids[1].status === 'missing'; @@ -90,7 +89,7 @@ revLimit = revLimit || 1000; var newEdits = opts.new_edits; var wasDelete = 'was_delete' in opts; - var idsToDocs = new Map(); + var idsToDocs = {}; var docsDone = 0; var docsToDo = docInfos.length; @@ -107,27 +106,33 @@ api[fun](currentDocInfo, {ctx: tx}, afterLocalPutOrRemove(i, results, checkAllDocsDone)); } else { var currentDocId = currentDocInfo.metadata.id; - if (idsToDocs.has(currentDocId)) { + var currentKey = '$' + currentDocId; + var currentValue = idsToDocs[currentKey]; + if (currentValue) { docsToDo--; // duplicate - idsToDocs.get(currentDocId).push([currentDocInfo, i]); + currentValue.push([currentDocInfo, i]); } else { - idsToDocs.set(currentDocId, [[currentDocInfo, i]]); + idsToDocs[currentKey] = [[currentDocInfo, i]]; } } } // in the case of new_edits, the user can provide multiple docs // with the same id. these need to be processed sequentially - idsToDocs.forEach(function (docs, id) { - if (docs.length === 1) { // fast case - var thisDoc = docs[0]; - mergeOrUpdateDoc(id, fetchedDocs, thisDoc[0], results, thisDoc[1], revLimit, newEdits, - wasDelete, writeDoc, checkAllDocsDone); - } else { // slow case - processsMultipleDocsWithSameId(id, docs, fetchedDocs, results, revLimit, newEdits, - wasDelete, writeDoc, checkAllDocsDone); + for (var thisKey in idsToDocs) { + if (idsToDocs.hasOwnProperty(thisKey)) { + var id = thisKey.substring(1); // cut off initial '$' + var docs = idsToDocs[thisKey]; + if (docs.length === 1) { // fast case + var thisDoc = docs[0]; + mergeOrUpdateDoc(id, fetchedDocs, thisDoc[0], results, thisDoc[1], revLimit, newEdits, + wasDelete, writeDoc, checkAllDocsDone); + } else { // slow case + processsMultipleDocsWithSameId(id, docs, fetchedDocs, results, revLimit, newEdits, + wasDelete, writeDoc, checkAllDocsDone); + } } - }); + } } export default processDocs;