UNPKG

@shared-state/persist

Version:

此软件包提供状态持久化功能

25 lines (24 loc) 959 B
import { SharedState } from "@shared-state/core"; export declare type PersistentValue<T = any> = { value: T; version?: string | number | undefined; }; export declare type PersistentStorage<T> = { get: (key: string) => (T | null) | Promise<T | null>; set: (key: string, value: T) => void | Promise<void>; remove: (key: string) => void; subscribe: (key: string, handler: (nextValue: T | null, previousValue: T | null) => void) => () => void; }; export declare type PersistedSharedState<T> = SharedState<T> & { hydrate: () => void; hydrationState: SharedState<boolean>; }; export declare type PersistentOptions<T> = { key: string; storage: PersistentStorage<PersistentValue<T>>; version?: string | number; migrate?: (value: any, version: string | number | undefined) => T; onHydrationStart?: () => void; onHydrationEnd?: () => void; onHydrationFailed?: (error: any) => void; };