import { CreatePersistentConfigInterface, Persistent, PersistentKey } from '../storages'; import type { EnhancedState } from './state.enhanced'; export declare class StatePersistent extends Persistent { state: () => EnhancedState; onMigrate?: (value: any) => ValueType; onSave?: (value: ValueType) => any; static storeValueSideEffectKey: string; /** * Internal Class for managing the permanent persistence of a State. * * @internal * @param state - State to be persisted. * @param config - Configuration object */ constructor(state: EnhancedState, config?: CreateStatePersistentConfigInterface); /** * Loads the persisted value into the State * or persists the State value in the corresponding Storage. * This behaviour depends on whether the State has been persisted before. * * @internal */ initialLoading(): Promise; /** * Loads the State from the corresponding Storage * and sets up side effects that dynamically update * the Storage value when the State changes. * * @internal * @param storageItemKey - Storage key of the to load State Instance. * | default = Persistent.key | * @return Whether the loading of the persisted State Instance and the setting up of the corresponding side effects was successful. */ loadPersistedValue(storageItemKey?: PersistentKey): Promise; /** * Persists the State in the corresponding Storage * and sets up side effects that dynamically update * the Storage value when the State changes. * * @internal * @param storageItemKey - Storage key of the to persist State Instance. * | default = Persistent.key | * @return Whether the persisting of the State Instance and setting up of the corresponding side effects was successful. */ persistValue(storageItemKey?: PersistentKey): Promise; /** * Sets up side effects to keep the Storage value in sync * with the current State value. * * @internal * @param storageItemKey - Storage key of the persisted State Instance. * | default = Persistent.key | */ setupSideEffects(storageItemKey?: PersistentKey): void; /** * Removes the State from the corresponding Storage. * -> State is no longer persisted * * @internal * @param storageItemKey - Storage key of the to remove State Instance. * | default = Persistent.key | * @return Whether the removal of the persisted State Instance was successful. */ removePersistedValue(storageItemKey?: PersistentKey): Promise; /** * Formats the specified key so that it can be used as a valid Storage key * and returns the formatted variant of it. * * If no formatable key (`undefined`/`null`) was provided, * an attempt is made to use the State identifier key as Storage key. * * @internal * @param key - Storage key to be formatted. */ formatKey(key: PersistentKey | undefined | null): PersistentKey | undefined; /** * Rebuilds Storage value based on the current State value. * * @internal * @param state - State whose current value to be applied to the Storage value. * @param storageItemKey - Storage key of the persisted State Instance. * | default = Persistent.key | * @param config - Configuration object */ rebuildStorageSideEffect(state: EnhancedState, storageItemKey: PersistentKey, config?: { [key: string]: any; }): void; } export interface CreateStatePersistentConfigInterface extends CreatePersistentConfigInterface { /** * Method used to format the loaded value before migrating it into the State. * @default undefined */ onMigrate?: (value: any) => ValueType; /** * Method used to format the to persist value before persisting it into the external storage. * @default undefined */ onSave?: (value: ValueType) => any; }