Skip to content

Commit

Permalink
refactor: renames private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Gancho Radkov committed Nov 9, 2023
1 parent 178d7bd commit ceb90e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions misc/keyvaluestorage/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,44 @@ export class KeyValueStorage implements IKeyValueStorage {
this.storage = local;
try {
const indexed = new IndexedDb();
migrate(local, indexed, this.isInitialized);
migrate(local, indexed, this.setInitialized);
// indexedDb isn't available in node env so this will throw
} catch (e) {
this.initialized = true;
}
}

private isInitialized = (store: IKeyValueStorage) => {
private setInitialized = (store: IKeyValueStorage) => {
this.storage = store;
this.initialized = true;
};

public async getKeys(): Promise<string[]> {
await this.initilization();
await this.initialize();
return this.storage.getKeys();
}

public async getEntries<T = any>(): Promise<[string, T][]> {
await this.initilization();
await this.initialize();
return this.storage.getEntries();
}

public async getItem<T = any>(key: string): Promise<T | undefined> {
await this.initilization();
await this.initialize();
return this.storage.getItem(key);
}

public async setItem<T = any>(key: string, value: T): Promise<void> {
await this.initilization();
await this.initialize();
return this.storage.setItem(key, value);
}

public async removeItem(key: string): Promise<void> {
await this.initilization();
await this.initialize();
return this.storage.removeItem(key);
}

private async initilization() {
private async initialize() {
if (this.initialized) {
return;
}
Expand Down
16 changes: 8 additions & 8 deletions misc/keyvaluestorage/src/node-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ export class KeyValueStorage implements IKeyValueStorage {
this.database = Db.create({
dbName,
});
migrate(dbName, this.database, this.isInitialized);
migrate(dbName, this.database, this.setInitialized);
}

private isInitialized = () => {
private setInitialized = () => {
this.initialized = true;
};

public async getKeys(): Promise<string[]> {
await this.initilization();
await this.initialize();
return this.database.getKeys();
}

public async getEntries<T = any>(): Promise<[string, T][]> {
await this.initilization();
await this.initialize();
return this.database.getEntries();
}

public async getItem<T = any>(key: string): Promise<T | undefined> {
await this.initilization();
await this.initialize();
return this.database.getItem(key);
}

public async setItem<_T = any>(key: string, value: any): Promise<void> {
await this.initilization();
await this.initialize();
await this.database.setItem(key, value);
}

public async removeItem(key: string): Promise<void> {
await this.initilization();
await this.initialize();
await this.database.removeItem(key);
}

private async initilization() {
private async initialize() {
if (this.initialized) {
return;
}
Expand Down

0 comments on commit ceb90e3

Please sign in to comment.