From b882e0ef8a640a6cdef512401f93c67ea9321d69 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 26 Jun 2019 22:02:00 +0200 Subject: [PATCH] respect argument count of idb calls lumia doesn't like undefined arguments if they are being left out, so call the idb calls with the exact amount of arguments --- src/matrix/storage/idb/query-target.js | 20 ++++++++++++++++---- src/matrix/storage/idb/utils.js | 4 +++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/matrix/storage/idb/query-target.js b/src/matrix/storage/idb/query-target.js index ec5c4530..a5c38b15 100644 --- a/src/matrix/storage/idb/query-target.js +++ b/src/matrix/storage/idb/query-target.js @@ -5,6 +5,18 @@ export default class QueryTarget { this._target = target; } + _openCursor(range, direction) { + if (range && direction) { + return this._target.openCursor(range, direction); + } else if (range) { + return this._target.openCursor(range); + } else if (direction) { + return this._target.openCursor(null, direction); + } else { + return this._target.openCursor(); + } + } + get(key) { return reqAsPromise(this._target.get(key)); } @@ -34,7 +46,7 @@ export default class QueryTarget { } async selectAll(range, direction) { - const cursor = this._target.openCursor(range, direction); + const cursor = this._openCursor(range, direction); const results = []; await iterateCursor(cursor, (value) => { results.push(value); @@ -97,7 +109,7 @@ export default class QueryTarget { _reduce(range, reducer, initialValue, direction) { let reducedValue = initialValue; - const cursor = this._target.openCursor(range, direction); + const cursor = this._openCursor(range, direction); return iterateCursor(cursor, (value) => { reducedValue = reducer(reducedValue, value); return {done: false}; @@ -111,7 +123,7 @@ export default class QueryTarget { } async _selectWhile(range, predicate, direction) { - const cursor = this._target.openCursor(range, direction); + const cursor = this._openCursor(range, direction); const results = []; await iterateCursor(cursor, (value) => { results.push(value); @@ -121,7 +133,7 @@ export default class QueryTarget { } async _find(range, predicate, direction) { - const cursor = this._target.openCursor(range, direction); + const cursor = this._openCursor(range, direction); let result; const found = await iterateCursor(cursor, (value) => { const found = predicate(value); diff --git a/src/matrix/storage/idb/utils.js b/src/matrix/storage/idb/utils.js index f5b73cf3..367d5e7d 100644 --- a/src/matrix/storage/idb/utils.js +++ b/src/matrix/storage/idb/utils.js @@ -44,8 +44,10 @@ export function iterateCursor(cursor, processValue) { const {done, jumpTo} = processValue(cursor.value, cursor.key); if (done) { resolve(true); - } else { + } else if(jumpTo) { cursor.continue(jumpTo); + } else { + cursor.continue(); } }; }).catch(err => {