Skip to content

Instantly share code, notes, and snippets.

@chapel
Created February 21, 2016 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapel/0e9f81007a5db2037ac6 to your computer and use it in GitHub Desktop.
Save chapel/0e9f81007a5db2037ac6 to your computer and use it in GitHub Desktop.
import { combineReducers } from 'redux'
import { createAction, reduceActions } from './playground';
export const addTodo = createAction('ADD_TODO', combineReducers({
todos(state = [], text) {
return [
{
id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
completed: false,
text
},
...state
];
},
history(state = {}, text) {
return {
...state,
lastEnteredText: text
};
}
}));
export const reducer = reduceActions([
addTodo
], {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment