mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
adding a redux todo list to playground
This commit is contained in:
15
playground/src/reducers/createReducer.ts
Normal file
15
playground/src/reducers/createReducer.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Reducer } from 'redux';
|
||||
import { ActionTypes, TodoAction } from '../actions';
|
||||
|
||||
export function createReducer<T>(
|
||||
initialState: T,
|
||||
handlers: { [actionType in ActionTypes]?: (state: T, action: TodoAction) => T }
|
||||
): Reducer<T> {
|
||||
return function reducer(state = initialState, action: TodoAction): T {
|
||||
if (handlers.hasOwnProperty(action.type)) {
|
||||
return handlers[action.type](state, action);
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user