majorly overhauled 2.8

This commit is contained in:
Ken
2019-02-26 21:27:23 -08:00
parent a84b72ae08
commit fdd6d11791
13 changed files with 214 additions and 251 deletions

View File

@@ -1,33 +1,21 @@
import { Store } from '../store';
import { addTodo, remove, complete, clear, setFilter } from './pureFunctions';
import { combineReducers } from 'redux';
import { createReducer } from 'redux-starter-kit';
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);
const todoReducer = createReducer<Store['todos']>(
{},
{
addTodo,
remove,
clear,
complete
}
);
return state;
}
function filterReducer(state: Store['filter'] = 'all', action: any): Store['filter'] {
switch (action.type) {
case 'setFilter':
return setFilter(state, action.filter);
}
return state;
}
const filterReducer = createReducer<Store['filter']>('all', {
setFilter
});
export const reducer = combineReducers({
todos: todoReducer,