@ffsm/store
Version:
A powerful state management library for React, providing a simple and efficient way to manage application state with built-in support for serialization, deserialization, and type safety.
32 lines (31 loc) • 1.32 kB
TypeScript
export interface PayloadAction<Payload = never, Type = string> {
type: Type;
payload: Payload;
}
export interface SliceReducerParam<State, Payload> {
(state: State, payload: PayloadAction<Payload>): State | void;
}
export interface SliceReducerNone<State> {
(state: State): State | void;
}
export interface SliceReducers<State, Payload = never> {
[x: string]: SliceReducerNone<State> | SliceReducerParam<State, Payload>;
}
export interface CreateSliceOptions<State, Reducers extends {}> {
name: string;
initialState: State;
reducers: Reducers;
}
export interface ReducerParam<Payload, Type = string> {
(payload: Payload): PayloadAction<Payload, Type>;
}
export interface ReducerNone<Payload = never, Type = string> {
(): PayloadAction<Payload, Type>;
}
export interface CreateSliceReturn<State, Reducers extends SliceReducers<State>> {
actions: {
[K in keyof Reducers]: Reducers[K] extends SliceReducerNone<State> ? SliceReducerNone<State> : Reducers[K] extends SliceReducerParam<State, infer P> ? ReducerParam<P> : ReducerNone;
};
reducer: (state: State, action: PayloadAction) => State | void;
}
export declare function createSlice<State, Reducers extends SliceReducers<State>>(options: CreateSliceOptions<State, Reducers>): CreateSliceReturn<State, Reducers>;