Skip to content

Commit

Permalink
[FIX] : type of storages function
Browse files Browse the repository at this point in the history
  • Loading branch information
masoud-shahpoori committed Nov 1, 2024
1 parent 70708a5 commit 015b5d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/persistor/persistReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function persistReducer<S, A extends Action>(
return baseReducer(state, action);

case PURGE_PERSIST_ACTION:
storage.clear(() => {}).then();
storage.removeItem(PERSIST_STORAGE_NAME).then();
isPaused = true;
return baseReducer(state, action);
default:
Expand Down
6 changes: 3 additions & 3 deletions src/persistor/persistStorage/DBStoragePersistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DBStoragePersistor implements StorageInterface {
async removeItem(
key: string,
callback?: (error?: Error) => void
): Promise<undefined> {
): Promise<undefined | unknown> {
await this.dbReady;

if (!this.db) throw new Error('Database not initialized');
Expand All @@ -104,7 +104,7 @@ export class DBStoragePersistor implements StorageInterface {

async getAllKeys(
callback?: (error?: Error, keys?: Array<string>) => void
): Promise<string[]> {
): Promise<string[] | unknown> {
await this.dbReady;

if (!this.db) throw new Error('Database not initialized');
Expand All @@ -130,7 +130,7 @@ export class DBStoragePersistor implements StorageInterface {
});
}

async clear(callback?: (error?: Error) => void): Promise<boolean> {
async clear(callback?: (error?: Error) => void): Promise<boolean | unknown> {
await this.dbReady;

if (!this.db) throw new Error('Database not initialized');
Expand Down
2 changes: 1 addition & 1 deletion src/persistor/persistStorage/DBStorageSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DBStorageSingleton {
return DBStorageSingleton.instance;
}

private async initPersistDb(): Promise<void> {
private async initPersistDb(): Promise<void | unknown> {
return new Promise((resolve, reject) => {
const request = indexedDB.open(PERSIST_STORAGE_NAME, 1);

Expand Down
12 changes: 6 additions & 6 deletions src/persistor/persistStorage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { DBStoragePersistor } from './DBStoragePersistor';
export type StorageType = 'localStorage' | 'sessionStorage' | 'indexedDB';

export const storageBuilder = (name: StorageType): StorageInterface => {
const hashTable: Record<StorageType, StorageInterface> = {
localStorage: new LocalStoragePersistor(),
sessionStorage: new SessionStoragePersistor(),
indexedDB: new DBStoragePersistor(),
};
if (name === 'indexedDB') {
return new DBStoragePersistor();
} else if (name === 'sessionStorage') {
return new SessionStoragePersistor();
}

return hashTable[name] as StorageInterface;
return new LocalStoragePersistor();
};

0 comments on commit 015b5d3

Please sign in to comment.