Skip to content

Commit 0c6fadd

Browse files
committed
[Examples] Add modified date to todomvc
Demo for #468
1 parent 038f687 commit 0c6fadd

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

examples/todomvc/reducers/todos.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_CO
33
const initialState = [{
44
text: 'Use Redux',
55
completed: false,
6+
modified: new Date(),
67
id: 0
78
}];
89

@@ -12,6 +13,7 @@ export default function todos(state = initialState, action) {
1213
return [{
1314
id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
1415
completed: false,
16+
modified: new Date(),
1517
text: action.text
1618
}, ...state];
1719

@@ -23,21 +25,21 @@ export default function todos(state = initialState, action) {
2325
case EDIT_TODO:
2426
return state.map(todo =>
2527
todo.id === action.id ?
26-
Object.assign({}, todo, { text: action.text }) :
28+
Object.assign({}, todo, { text: action.text, modified: new Date() }) :
2729
todo
2830
);
2931

3032
case COMPLETE_TODO:
3133
return state.map(todo =>
3234
todo.id === action.id ?
33-
Object.assign({}, todo, { completed: !todo.completed }) :
35+
Object.assign({}, todo, { completed: !todo.completed, modified: new Date() }) :
3436
todo
3537
);
3638

3739
case COMPLETE_ALL:
3840
const areAllMarked = state.every(todo => todo.completed);
3941
return state.map(todo => Object.assign({}, todo, {
40-
completed: !areAllMarked
42+
completed: !areAllMarked, modified: new Date()
4143
}));
4244

4345
case CLEAR_COMPLETED:

examples/todomvc/store/configureStore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as actionCreators from '../actions';
44

55
export default function configureStore(preloadedState) {
66
const enhancer = window.__REDUX_DEVTOOLS_EXTENSION__ &&
7-
window.__REDUX_DEVTOOLS_EXTENSION__({ actionCreators });
7+
window.__REDUX_DEVTOOLS_EXTENSION__({ actionCreators, serialize: true });
88
if (!enhancer) {
99
console.warn('Install Redux DevTools Extension to inspect the app state: ' +
1010
'https://github.com/zalmoxisus/redux-devtools-extension#installation')

0 commit comments

Comments
 (0)