From b00db37bf4c05045815859cb3de58c708715328e Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 19 Sep 2020 15:06:27 +0000 Subject: [PATCH] fix(core): update --- test/test.browser.ts | 4 ---- ts/webstore.classes.webstore.ts | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/test.browser.ts b/test/test.browser.ts index a74c863..7ae8973 100644 --- a/test/test.browser.ts +++ b/test/test.browser.ts @@ -11,10 +11,6 @@ tap.test('first test', async () => { 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 () => { await testWebstore.set('mystring', 'heythere'); expect(await testWebstore.get('mystring')).to.equal('heythere'); diff --git a/ts/webstore.classes.webstore.ts b/ts/webstore.classes.webstore.ts index 5c62e3d..4d25681 100644 --- a/ts/webstore.classes.webstore.ts +++ b/ts/webstore.classes.webstore.ts @@ -18,7 +18,8 @@ export class WebStore { public async init() { if (this.initCalled) { - return this.readyDeferred.promise; + await this.readyDeferred.promise; + return; } this.initCalled = true; this.db = await plugins.idb.openDB(this.options.dbName, 1, { @@ -27,6 +28,7 @@ export class WebStore { }, }); this.readyDeferred.resolve(); + return; } async get(key: string): Promise { @@ -41,6 +43,7 @@ export class WebStore { } async set(key: string, val: T) { + await this.init(); return this.db.put(this.options.storeName, val, key); }