Compare commits

..

2 Commits

Author SHA1 Message Date
00964a7db1 1.0.14 2020-09-19 15:06:28 +00:00
b00db37bf4 fix(core): update 2020-09-19 15:06:27 +00:00
4 changed files with 6 additions and 7 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webstore", "name": "@pushrocks/webstore",
"version": "1.0.13", "version": "1.0.14",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webstore", "name": "@pushrocks/webstore",
"version": "1.0.13", "version": "1.0.14",
"private": false, "private": false,
"description": "high performance storage in the browser using indexed db", "description": "high performance storage in the browser using indexed db",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

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);
} }