mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
36 lines
821 B
TypeScript
36 lines
821 B
TypeScript
import { Store } from '../store';
|
|
import { addTodo, remove, complete, clear, setFilter } from './pureFunctions';
|
|
import { combineReducers } from 'redux';
|
|
|
|
function todoReducer(state: Store['todos'] = {}, action: any): Store['todos'] {
|
|
switch (action.type) {
|
|
case 'addTodo':
|
|
return addTodo(state, action.id, action.label);
|
|
|
|
case 'remove':
|
|
return remove(state, action.id);
|
|
|
|
case 'clear':
|
|
return clear(state);
|
|
|
|
case 'complete':
|
|
return complete(state, action.id);
|
|
}
|
|
|
|
return state;
|
|
}
|
|
|
|
function filterReducer(state: Store['filter'] = 'all', action: any): Store['filter'] {
|
|
switch (action.type) {
|
|
case 'setFilter':
|
|
return setFilter(state, action.filter);
|
|
}
|
|
|
|
return state;
|
|
}
|
|
|
|
export const reducer = combineReducers({
|
|
todos: todoReducer,
|
|
filter: filterReducer
|
|
});
|