UNPKG

@alauda-fe/common

Version:

Alauda frontend team common codes.

36 lines (35 loc) 1.24 kB
import { MonoTypeOperatorFunction, Observable } from 'rxjs'; export declare class CacheStore<P, V> { private readonly fetcher; private readonly share; private readonly validator; private readonly store; constructor({ fetcher, share, validator }: CacheStoreOptions<P, V>); fetchState(params: P): Observable<CacheLoadState<V>>; fetch(params: P): Observable<V>; refetch(params: P): void; refetchAll(): void; get(params: P): Cache<V>; has(params: P): boolean; delete(params: P): void; clear(): void; forEach: (callbackfn: (value: Cache<V>, key: P, map: Map<P, Cache<V>>) => void, thisArg?: any) => void; entries: () => IterableIterator<[P, Cache<V>]>; values: () => IterableIterator<Cache<V>>; keys: () => IterableIterator<P>; } export interface CacheStoreOptions<P, V> { fetcher: (params: P) => Observable<V>; share?: <T>() => MonoTypeOperatorFunction<T>; validator?: (loadState: CacheLoadState<V>) => boolean; } export interface CacheLoadState<V> { state: 'loading' | 'loaded' | 'loadFailed'; result?: V; error?: unknown; } export interface Cache<V> { loadState: Observable<CacheLoadState<V>>; refetch: () => void; finish: () => void; }