Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
00964a7db1 | |||
b00db37bf4 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -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": {
|
||||||
|
@ -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",
|
||||||
|
@ -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');
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user