/*! * * Copyright 2017 - acrazing * * @author acrazing joking.young@gmail.com * @since 2017-11-28 17:31:44 * @version 1.0.0 * @desc sync.ts */ import { IReactionDisposer } from 'mobx'; export interface SyncStorage { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; } /** * sync trunk initial options */ export interface SyncTrunkOptions { /** * storage, SyncStorage only * default is localStorage */ storage?: SyncStorage; /** * the storage key, default is KeyDefaultKey */ storageKey?: string; /** * the delay time, default is 0 */ delay?: number; /** * error callback * @param error */ onError?: (error: any) => void; } export declare class SyncTrunk { disposer: IReactionDisposer; private store; private storage; readonly storageKey: string; readonly delay: number; readonly onError: (error: any) => void; constructor(store: any, { storage, storageKey, delay, onError, }?: SyncTrunkOptions); persist(): void; /** * init the store */ init(initialState?: any): void; clear(): void; updateStore(store: any): void; }