mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
19 lines
712 B
TypeScript
19 lines
712 B
TypeScript
// create-reducer.ts
|
|
import { Action } from 'redux';
|
|
|
|
type Handlers<State, Types extends string, Actions extends Action<Types>> = {
|
|
readonly [Type in Types]: (state: State, action: Actions) => State
|
|
}
|
|
|
|
// export const createReducer = <State, Types extends string, Actions extends Action<Types>>(
|
|
// initialState: State,
|
|
// handlers: Handlers<State, Types, Actions>,
|
|
// ) => (state = initialState, action: Actions) =>
|
|
// handlers.hasOwnProperty(action.type) ? handlers[action.type as Types](state, action) : state;
|
|
|
|
export const createReducer = (
|
|
initialState,
|
|
handlers,
|
|
) => (state = initialState, action) => (handlers.hasOwnProperty(action.type)
|
|
? handlers[action.type](state, action)
|
|
: state);
|