Skip to content

Commit

Permalink
[Examples] Add modified date to todomvc
Browse files Browse the repository at this point in the history
Demo for #468
  • Loading branch information
zalmoxisus committed Dec 3, 2018
1 parent 038f687 commit 0c6fadd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions examples/todomvc/reducers/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_CO
const initialState = [{
text: 'Use Redux',
completed: false,
modified: new Date(),
id: 0
}];

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

Expand All @@ -23,21 +25,21 @@ export default function todos(state = initialState, action) {
case EDIT_TODO:
return state.map(todo =>
todo.id === action.id ?
Object.assign({}, todo, { text: action.text }) :
Object.assign({}, todo, { text: action.text, modified: new Date() }) :
todo
);

case COMPLETE_TODO:
return state.map(todo =>
todo.id === action.id ?
Object.assign({}, todo, { completed: !todo.completed }) :
Object.assign({}, todo, { completed: !todo.completed, modified: new Date() }) :
todo
);

case COMPLETE_ALL:
const areAllMarked = state.every(todo => todo.completed);
return state.map(todo => Object.assign({}, todo, {
completed: !areAllMarked
completed: !areAllMarked, modified: new Date()
}));

case CLEAR_COMPLETED:
Expand Down
2 changes: 1 addition & 1 deletion examples/todomvc/store/configureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as actionCreators from '../actions';

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

0 comments on commit 0c6fadd

Please sign in to comment.