-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducers.js
41 lines (36 loc) · 1020 Bytes
/
reducers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {ADD_TODO, COMPLETE_TODO, SET_VISIBILITY_FILTER, VisibilityFilters} from './actions';
import { combineReducers } from 'redux';
const { SHOW_ALL } = VisibilityFilters;
function visibilityFilter(state=SHOW_ALL, action) {
switch (action.type) {
case SET_VISIBILITY_FILTER:
return action.filter;
default:
return state;
}
}
function todos(state=[], action) {
switch (action.type) {
case ADD_TODO:
return [
...state,
{
text: action.text,
completed: false
}
];
case COMPLETE_TODO:
return [
...state.slice(0, action.index),
Object.assign({}, state[action.index], {completed: true}),
...state.slice(action.index + 1)
];
default:
return state
}
}
const todoApp = combineReducers({
visibilityFilter,
todos
});
export default todoApp;