mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
majorly overhauled 2.8
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user