Skip to content

Instantly share code, notes, and snippets.

@JaySunSyn
Created January 17, 2018 17:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JaySunSyn/7fdb4c9900645234e26085ffa162b697 to your computer and use it in GitHub Desktop.
Step 2
<script src="../../node_modules/redux/dist/redux.min.js"></script>
<script>
(() => {
const initialState = {
todos: [
{text: 'Buy Veggies'},
{text: 'Buy Fruits'},
{text: 'Buy Pizza'},
],
};
const todoReducer = (state, action) => {
if (!state) {
return initialState;
}
let todos;
switch (action.type) {
case 'ADD_TODO':
todos = state.todos.slice(0);
todos.push(action.todo);
return Object.assign({}, state, {todos: todos});
case 'REMOVE_TODO':
todos = state.todos.slice(0);
todos.splice(todos.indexOf(action.todo), 1);
return Object.assign({}, state, {todos: todos});
default:
return state;
}
};
App = window.App || {};
App.rootReducer = Redux.combineReducers({
todo: todoReducer,
// Another reducer ...
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment