1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00
This commit is contained in:
muerwre 2019-08-02 17:17:09 +07:00
parent 132fe872b6
commit e5bc0d258f
17 changed files with 301 additions and 65 deletions

19
src/utils/reducer.ts Normal file
View file

@ -0,0 +1,19 @@
// 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;