MCPcopy
hub / github.com/zalmoxisus/redux-devtools-extension / todos

Function todos

examples/todomvc/reducers/todos.js:10–51  ·  view source on GitHub ↗
(state = initialState, action)

Source from the content-addressed store, hash-verified

8}];
9
10export default function todos(state = initialState, action) {
11 switch (action.type) {
12 case ADD_TODO:
13 return [{
14 id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
15 completed: false,
16 modified: new Date(),
17 text: action.text
18 }, ...state];
19
20 case DELETE_TODO:
21 return state.filter(todo =>
22 todo.id !== action.id
23 );
24
25 case EDIT_TODO:
26 return state.map(todo =>
27 todo.id === action.id ?
28 Object.assign({}, todo, { text: action.text, modified: new Date() }) :
29 todo
30 );
31
32 case COMPLETE_TODO:
33 return state.map(todo =>
34 todo.id === action.id ?
35 Object.assign({}, todo, { completed: !todo.completed, modified: new Date() }) :
36 todo
37 );
38
39 case COMPLETE_ALL:
40 const areAllMarked = state.every(todo => todo.completed);
41 return state.map(todo => Object.assign({}, todo, {
42 completed: !areAllMarked, modified: new Date()
43 }));
44
45 case CLEAR_COMPLETED:
46 return state.filter(todo => todo.completed === false);
47
48 default:
49 return state;
50 }
51}

Callers 1

todos.spec.jsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…