Last active
December 30, 2017 00:47
-
-
Save francisngo/57ffc4694507bf2c673e5649d05c6142 to your computer and use it in GitHub Desktop.
Collection for Redux todo example - This file defines the reducer function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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