aboutsummaryrefslogtreecommitdiff
path: root/packages/idb-bridge
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-06-25 13:44:03 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-06-25 13:44:03 +0200
commitdf5619236b7328ce7cfb5d130948aa5200983919 (patch)
tree2392b9eb53cb562c2cf931949cdbfc10c9fed8bb /packages/idb-bridge
parentb3fc710d9a3b481196074ddd9a84a59be1f07fb3 (diff)
idb: extend test case
Diffstat (limited to 'packages/idb-bridge')
-rw-r--r--packages/idb-bridge/src/MemoryBackend.test.ts17
-rw-r--r--packages/idb-bridge/src/MemoryBackend.ts11
-rw-r--r--packages/idb-bridge/src/tree/interfaces.ts2
3 files changed, 28 insertions, 2 deletions
diff --git a/packages/idb-bridge/src/MemoryBackend.test.ts b/packages/idb-bridge/src/MemoryBackend.test.ts
index 2e322dfa6..c21c2d064 100644
--- a/packages/idb-bridge/src/MemoryBackend.test.ts
+++ b/packages/idb-bridge/src/MemoryBackend.test.ts
@@ -214,6 +214,23 @@ test("Spec: Example 1 Part 3", async t => {
cursor = request6.result;
t.is(cursor, null);
+
+ const request7 = index5.openCursor(null, "prevunique");
+ await promiseFromRequest(request7);
+ cursor = request7.result;
+ t.is(cursor.value.author, "Fred");
+ t.is(cursor.value.isbn, 234567);
+ cursor.continue();
+
+ await promiseFromRequest(request7);
+ cursor = request7.result;
+ t.is(cursor.value.author, "Barney");
+ cursor.continue();
+
+ await promiseFromRequest(request7);
+ cursor = request7.result;
+ t.is(cursor, null);
+
db.close();
t.pass();
diff --git a/packages/idb-bridge/src/MemoryBackend.ts b/packages/idb-bridge/src/MemoryBackend.ts
index 786fa4cf6..694daacfa 100644
--- a/packages/idb-bridge/src/MemoryBackend.ts
+++ b/packages/idb-bridge/src/MemoryBackend.ts
@@ -640,7 +640,16 @@ export class MemoryBackend implements Backend {
objectStoreProperties.indexes.push(indexName);
schema.indexes[indexName] = indexProperties;
- // FIXME: build index from existing object store!
+ const objectStore = myConn.objectStoreMap[objectStoreName];
+ if (!objectStore) {
+ throw Error("object store does not exist");
+ }
+
+ const storeData = objectStore.modifiedData || objectStore.originalData;
+
+ storeData.forEach((v, k) => {
+ this.insertIntoIndex(newIndex, k, v.value, indexProperties);
+ });
}
async deleteRecord(
diff --git a/packages/idb-bridge/src/tree/interfaces.ts b/packages/idb-bridge/src/tree/interfaces.ts
index c708c20b5..6bd0cdf58 100644
--- a/packages/idb-bridge/src/tree/interfaces.ts
+++ b/packages/idb-bridge/src/tree/interfaces.ts
@@ -53,7 +53,7 @@ export interface IMapSource<K=any, V=any> extends ISetSource<K>
/** Calls callbackFn once for each key-value pair present in the map object.
* The ES6 Map class sends the value to the callback before the key, so
* this interface must do likewise. */
- forEach(callbackFn: (v:V, k:K, map:IMapSource<K,V>) => void, thisArg: any): void;
+ forEach(callbackFn: (v:V, k:K, map:IMapSource<K,V>) => void, thisArg?: any): void;
/** Returns an iterator that provides all key-value pairs from the collection (as arrays of length 2). */
entries(): IterableIterator<[K,V]>;