berish-stober
Version:
Библиотека расширенного манипулирования хранилищем. Позволяет расширять функционал хранения данных посредством специальных обработчиков
36 lines (35 loc) • 1.59 kB
TypeScript
import { Storage } from './storage';
export interface IAction {
type: string;
[key: string]: any;
}
export declare type IReducer<State> = (state: State, action: IAction) => State;
export declare type ISubscriber<Store, State> = (store: Store, newState: State) => any;
export interface IStoreAdapter<State> {
getState: () => State;
dispatch: (action: IAction) => void;
subscribe: (listener: () => void) => (() => void);
replaceReducer: (reducer: IReducer<State>) => void;
}
export declare type StoreAdapterFabric<State> = (reducer: IReducer<State>, initialState?: any) => IStoreAdapter<State>;
export declare class Store<State = any> {
state: State;
protected storeAdapterFabric: StoreAdapterFabric<State>;
protected storeAdapter: IStoreAdapter<State>;
protected reducers: Array<IReducer<State>>;
protected callbacks: Array<ISubscriber<this, State>>;
protected stateSymbol: symbol;
protected storage: Storage;
protected isEmittedByDispatch: boolean;
constructor(storeAdapterFabric: StoreAdapterFabric<State>, reducers: Array<IReducer<State>>, initialState?: State);
setStorage(storage: Storage): this;
dispatch<T extends IAction>(action: T): Promise<void>;
subscribe(config: ISubscriber<this, State>): () => void;
loadState(): Promise<any>;
clear(): Promise<void>;
get<Key extends keyof State>(key: Key): State[Key];
set<Key extends keyof State>(key: Key, value: State[Key]): void;
protected storeInitialized(): void;
protected storeSubscribed(): void;
protected storeUnsubscribed(): void;
}