fix(core): update

This commit is contained in:
Philipp Kunz 2020-09-19 15:06:27 +00:00
parent 995ae20502
commit b00db37bf4
2 changed files with 4 additions and 5 deletions

View File

@ -11,10 +11,6 @@ tap.test('first test', async () => {
expect(testWebstore).to.be.instanceOf(webstore.WebStore); expect(testWebstore).to.be.instanceOf(webstore.WebStore);
}); });
tap.test('should init the database', async () => {
await testWebstore.init();
});
tap.test('should allow storing a string', async () => { tap.test('should allow storing a string', async () => {
await testWebstore.set('mystring', 'heythere'); await testWebstore.set('mystring', 'heythere');
expect(await testWebstore.get('mystring')).to.equal('heythere'); expect(await testWebstore.get('mystring')).to.equal('heythere');

View File

@ -18,7 +18,8 @@ export class WebStore<T = any> {
public async init() { public async init() {
if (this.initCalled) { if (this.initCalled) {
return this.readyDeferred.promise; await this.readyDeferred.promise;
return;
} }
this.initCalled = true; this.initCalled = true;
this.db = await plugins.idb.openDB(this.options.dbName, 1, { this.db = await plugins.idb.openDB(this.options.dbName, 1, {
@ -27,6 +28,7 @@ export class WebStore<T = any> {
}, },
}); });
this.readyDeferred.resolve(); this.readyDeferred.resolve();
return;
} }
async get(key: string): Promise<T> { async get(key: string): Promise<T> {
@ -41,6 +43,7 @@ export class WebStore<T = any> {
} }
async set(key: string, val: T) { async set(key: string, val: T) {
await this.init();
return this.db.put(this.options.storeName, val, key); return this.db.put(this.options.storeName, val, key);
} }