From a52d86a39e9cca620823e3d97d7c129a7abafced Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 14 Mar 2021 22:51:20 -0400 Subject: Dictionary database improvements (#1527) * Update formatting * Add _findMultiBulk * Update implementation of findTermsBySequenceBulk * Update tests * Generalize query creation * Remove _findGenericBulk * Reduce function creation * Add more bindings * Simplify findTermsExactBulk implementation * Update var names * Update _findMultiBulk to support multiple index queries * Update findTermsBulk * Update getMedia implementation * Pass data arg to getAll and findFirst to avoid having multiple closures --- ext/js/data/database.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'ext/js/data') diff --git a/ext/js/data/database.js b/ext/js/data/database.js index f44ea1d9..a0a1804a 100644 --- a/ext/js/data/database.js +++ b/ext/js/data/database.js @@ -95,11 +95,11 @@ class Database { }); } - getAll(objectStoreOrIndex, query, resolve, reject) { + getAll(objectStoreOrIndex, query, resolve, reject, data) { if (typeof objectStoreOrIndex.getAll === 'function') { - this._getAllFast(objectStoreOrIndex, query, resolve, reject); + this._getAllFast(objectStoreOrIndex, query, resolve, reject, data); } else { - this._getAllUsingCursor(objectStoreOrIndex, query, resolve, reject); + this._getAllUsingCursor(objectStoreOrIndex, query, resolve, reject, data); } } @@ -116,25 +116,25 @@ class Database { const transaction = this.transaction([objectStoreName], 'readonly'); const objectStore = transaction.objectStore(objectStoreName); const objectStoreOrIndex = indexName !== null ? objectStore.index(indexName) : objectStore; - this.findFirst(objectStoreOrIndex, query, resolve, reject, predicate, predicateArg, defaultValue); + this.findFirst(objectStoreOrIndex, query, resolve, reject, null, predicate, predicateArg, defaultValue); }); } - findFirst(objectStoreOrIndex, query, resolve, reject, predicate, predicateArg, defaultValue) { + findFirst(objectStoreOrIndex, query, resolve, reject, data, predicate, predicateArg, defaultValue) { const noPredicate = (typeof predicate !== 'function'); const request = objectStoreOrIndex.openCursor(query, 'next'); - request.onerror = (e) => reject(e.target.error); + request.onerror = (e) => reject(e.target.error, data); request.onsuccess = (e) => { const cursor = e.target.result; if (cursor) { const {value} = cursor; if (noPredicate || predicate(value, predicateArg)) { - resolve(value); + resolve(value, data); } else { cursor.continue(); } } else { - resolve(defaultValue); + resolve(defaultValue, data); } }; } @@ -256,23 +256,23 @@ class Database { return false; } - _getAllFast(objectStoreOrIndex, query, resolve, reject) { + _getAllFast(objectStoreOrIndex, query, resolve, reject, data) { const request = objectStoreOrIndex.getAll(query); - request.onerror = (e) => reject(e.target.error); - request.onsuccess = (e) => resolve(e.target.result); + request.onerror = (e) => reject(e.target.error, data); + request.onsuccess = (e) => resolve(e.target.result, data); } - _getAllUsingCursor(objectStoreOrIndex, query, resolve, reject) { + _getAllUsingCursor(objectStoreOrIndex, query, resolve, reject, data) { const results = []; const request = objectStoreOrIndex.openCursor(query, 'next'); - request.onerror = (e) => reject(e.target.error); + request.onerror = (e) => reject(e.target.error, data); request.onsuccess = (e) => { const cursor = e.target.result; if (cursor) { results.push(cursor.value); cursor.continue(); } else { - resolve(results); + resolve(results, data); } }; } -- cgit v1.2.3