/*! * * Copyright 2017 - acrazing * * @author acrazing joking.young@gmail.com * @since 2017-11-28 17:31:44 * @version 1.0.0 * @desc async.ts */ import { IReactionDisposer } from 'mobx'; import { SyncStorage } from './sync'; /** * The async storage API */ export interface AsyncStorage { getItem(key: string): Promise; setItem(key: string, value: string): Promise; removeItem(key: string): Promise; } /** * the async trunk initial options */ export interface AsyncTrunkOptions { /** * storage, both AsyncStorage and SyncStorage is supported, * default is localStorage */ storage?: AsyncStorage | SyncStorage; /** * the custom persisted key in storage, * default is KeyDefaultKey */ storageKey?: string; /** * delay milliseconds for run the reaction for mobx, * default is 0 */ delay?: number; /** * error callback * @param error */ onError?: (error: any) => void; } export declare class AsyncTrunk { disposer: IReactionDisposer; private store; private storage; readonly storageKey: string; readonly delay: number; readonly onError: (error: any) => void; constructor(store: any, { storage, storageKey, delay, onError, }?: AsyncTrunkOptions); persist(): Promise; /** * init the trunk async */ init(initialState?: any): Promise; clear(): Promise; updateStore(store: any): Promise; }