fix(core): update
This commit is contained in:
@ -9,24 +9,33 @@ export class WebStore<T = any> {
|
||||
public db: plugins.idb.IDBPDatabase;
|
||||
public objectStore: plugins.idb.IDBPObjectStore;
|
||||
public options: IWebStoreOptions;
|
||||
private initCalled: boolean = false;
|
||||
private readyDeferred = plugins.smartpromise.defer();
|
||||
|
||||
constructor(optionsArg: IWebStoreOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
public async init() {
|
||||
if (this.initCalled) {
|
||||
return this.readyDeferred.promise;
|
||||
}
|
||||
this.initCalled = true;
|
||||
this.db = await plugins.idb.openDB(this.options.dbName, 1, {
|
||||
upgrade: (db) => {
|
||||
db.createObjectStore(this.options.storeName);
|
||||
},
|
||||
});
|
||||
this.readyDeferred.resolve();
|
||||
}
|
||||
|
||||
async get(key: string): Promise<T> {
|
||||
await this.init();
|
||||
return this.db.get(this.options.storeName, key);
|
||||
}
|
||||
|
||||
async check(keyArg: string): Promise<boolean> {
|
||||
await this.init();
|
||||
const result = await this.get(keyArg);
|
||||
return !!result;
|
||||
}
|
||||
@ -36,14 +45,17 @@ export class WebStore<T = any> {
|
||||
}
|
||||
|
||||
async delete(key: string) {
|
||||
await this.init();
|
||||
return this.db.delete(this.options.storeName, key);
|
||||
}
|
||||
|
||||
async clear() {
|
||||
await this.init();
|
||||
return this.db.clear(this.options.storeName);
|
||||
}
|
||||
|
||||
async keys() {
|
||||
await this.init();
|
||||
return this.db.getAllKeys(this.options.storeName);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,11 @@
|
||||
// pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
smartpromise
|
||||
};
|
||||
|
||||
// thirdparty scope
|
||||
import * as idb from 'idb';
|
||||
|
||||
export { idb };
|
||||
|
Reference in New Issue
Block a user