Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core/biblio-db): Move from indexedDB to idb #2228

Merged
merged 21 commits into from
Aug 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/core/biblio-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const readyPromise = openDB("respec-biblio2", 12, {
}
}),
];
Promise.all(promisesToCreateSchema);
},
});

Expand All @@ -61,7 +60,7 @@ export const biblioDB = {
if (await this.isAlias(id)) {
id = await this.resolveAlias(id);
}
return this.get("reference", id);
return await this.get("reference", id);
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
},
/**
* Checks if the database has an id for a given type.
Expand Down Expand Up @@ -115,8 +114,8 @@ export const biblioDB = {
.transaction("alias", "readonly")
.objectStore("alias");
const range = IDBKeyRange.only(id);
const request = await objectStore.openCursor(range);
return request ? request.value.aliasOf : request;
const result = await objectStore.openCursor(range);
return result ? result.value.aliasOf : result;
},
/**
* Get a reference or alias out of the database.
Expand All @@ -135,8 +134,8 @@ export const biblioDB = {
const db = await this.ready;
const objectStore = db.transaction([type], "readonly").objectStore(type);
const range = IDBKeyRange.only(id);
const request = await objectStore.openCursor(range);
return request ? request.value : request;
const result = await objectStore.openCursor(range);
return result ? result.value : result;
},
/**
* Adds references and aliases to database. This is usually the data from
Expand Down Expand Up @@ -175,7 +174,7 @@ export const biblioDB = {
const promisesToAdd = Object.keys(aliasesAndRefs)
.map(type => {
return Array.from(aliasesAndRefs[type]).map(details =>
this.add(type, details)
await this.add(type, details)
);
})
.reduce((collector, promises) => collector.concat(promises), []);
Expand Down Expand Up @@ -222,7 +221,7 @@ export const biblioDB = {
const storeNames = [...ALLOWED_TYPES];
const stores = await db.transaction(storeNames, "readwrite");
const clearStorePromises = storeNames.map(name => {
return stores.objectStore(name).clear();
return await stores.objectStore(name).clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant too. It still returns a Promise anyway.

});
Promise.all(clearStorePromises);
saschanaz marked this conversation as resolved.
Show resolved Hide resolved
},
Expand Down