Created
January 17, 2018 17:21
-
-
Save JaySunSyn/7fdb4c9900645234e26085ffa162b697 to your computer and use it in GitHub Desktop.
Step 2
This file contains hidden or 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
<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