Skip to content

Instantly share code, notes, and snippets.

@francisngo
Last active December 30, 2017 00:47
Show Gist options
  • Save francisngo/57ffc4694507bf2c673e5649d05c6142 to your computer and use it in GitHub Desktop.
Save francisngo/57ffc4694507bf2c673e5649d05c6142 to your computer and use it in GitHub Desktop.
Collection for Redux todo example - This file defines the reducer function
import { types } from './actions';
const initialState = {
todos: ['Plan web app', 'Analyze use of app', 'Design and develop app', 'Test app', 'Implement and maintain app']
};
export const reducer = (state = initialState, action) => {
const { todos } = state;
const { type, payload } = action;
switch (type) {
case types.ADDTODO: {
return {
...state,
todos: [payload, ...todos]
};
}
case types.REMOVETODO: {
return {
...state,
todos: todos.filter((todo, i) => i !== payload)
};
}
}
return state;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment