mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
13 lines
393 B
TypeScript
13 lines
393 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 = (
|
|
initialState,
|
|
handlers,
|
|
) => (state = initialState, action) => (handlers.hasOwnProperty(action.type)
|
|
? handlers[action.type](state, action)
|
|
: state);
|