IndexedDb for persist state? #125
-
Hi, please add support indexedDb for persist state, or please tell me the best way to implement it youself |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
You can provide a custom strategy. import * as localForage from 'localforage';
localForage.config({
driver: localForage.INDEXEDDB,
name: 'Elf',
version: 1.0,
storeName: 'elf',
});
export const persist = persistState(authStore, {
key: 'auth',
storage: localForage,
}); |
Beta Was this translation helpful? Give feedback.
-
Unfortunately Elf's StateStorage interface doesn't entirely match localForage signature. // Elf
export interface StateStorage {
getItem<T extends Record<string, any>>(key: string): MaybeAsync<T | undefined>;
setItem(key: string, value: Record<string, any>): MaybeAsync<boolean>;
removeItem(key: string): MaybeAsync<boolean>;
} // Akita
export interface PersistStateStorage {
getItem(key: string): MaybeAsync;
setItem(key: string, value: any): MaybeAsync;
clear(): void;
} // LocalForage
interface LocalForageDbMethodsCore {
getItem<T>(key: string, callback?: (err: any, value: T | null) => void): Promise<T | null>;
setItem<T>(key: string, value: T, callback?: (err: any, value: T) => void): Promise<T>;
removeItem(key: string, callback?: (err: any) => void): Promise<void>;
clear(callback?: (err: any) => void): Promise<void>;
// ...
} I think there are 3 incompatibilities:
We can workaround it, but it feels a bit clumsy. |
Beta Was this translation helpful? Give feedback.
-
@arochoab should work in v1.1.4 |
Beta Was this translation helpful? Give feedback.
You can provide a custom strategy.