Skip to content

Commit

Permalink
🐛 Make metadata store totally exception safe
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoLegends committed May 26, 2018
1 parent 2f88113 commit dcf6cdd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/actions/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ export class MetadataStore {
private db: Promise<DB>;

constructor() {
this.db = idb.open('Festify', 2, upgrade => {
if (upgrade.objectStoreNames.contains('metadata')) {
upgrade.deleteObjectStore('metadata');
}
const store = upgrade.createObjectStore('metadata', { keyPath: 'trackId' });
store.createIndex('dateCreated', 'dateCreated', { unique: false });
// Wrap IDB initialization to catch synchronous errors
this.db = new Promise((res, rej) => {
idb.open('Festify', 2, upgrade => {
if (upgrade.objectStoreNames.contains('metadata')) {
upgrade.deleteObjectStore('metadata');
}
const store = upgrade.createObjectStore('metadata', { keyPath: 'trackId' });
store.createIndex('dateCreated', 'dateCreated', { unique: false });
})
.then(res)
.catch(rej);
});
this.deleteOld();
}
Expand Down

0 comments on commit dcf6cdd

Please sign in to comment.