redux-store-helper
Version:
Provides the ability to create typed redux domain-based stores in a simple manner.
34 lines (33 loc) • 1.2 kB
TypeScript
import { AnyAction, Store as ReduxStore } from 'redux';
declare type StringMap = Record<string, any>;
export declare function setGlobalStore(store: AnyStore): void;
interface Action {
type: string;
payload: {
moduleName: string;
moduleState: any;
};
}
interface ConstructorParams<StoreGeneric extends StringMap> extends HelperCreatorParams {
name: string;
initialState: StoreGeneric;
}
declare class Store<StoreGeneric extends StringMap> {
private _moduleName;
private _initialState;
private _reducerName;
private _actionPrefix;
constructor({ name, initialState, reducerName, actionPrefix, }: ConstructorParams<StoreGeneric>);
setState(state: Partial<StoreGeneric>): void;
get state(): StoreGeneric;
}
declare type AnyStore = ReduxStore<any, AnyAction>;
interface HelperCreatorParams {
actionPrefix: string;
reducerName: string;
}
export declare const getStoreHelper: ({ actionPrefix, reducerName, }: HelperCreatorParams) => {
createStore<StoreGeneric>(name: string, initialState: StoreGeneric): Store<StoreGeneric>;
storeHelperReducer: (state: Record<string, any>, action: Action) => Record<string, any>;
};
export {};