Last active
January 17, 2018 11:13
-
-
Save JaySunSyn/f133253476257baa652269ca557daa67 to your computer and use it in GitHub Desktop.
Redux Polymer Todo Tutorial Step-1
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
<link rel="import" href="../../bower_components/polymer/polymer-element.html"> | |
<link rel="import" href="../../bower_components/polymer-redux/polymer-redux.html"> | |
<script> | |
const initialState = { | |
todos: [ | |
{text: 'Buy Veggies'}, | |
{text: 'Buy Fruits'}, | |
{text: 'Buy Pizza'}, | |
], | |
}; | |
const reducer = (state, action) => { | |
if (!state) { | |
return initialState; | |
} | |
const todos = state.todos.slice(0); | |
switch (action.type) { | |
case 'ADD_TODO': | |
todos.push(action.todo); | |
break; | |
case 'REMOVE_TODO': | |
todos.splice(todos.indexOf(action.todo), 1); | |
break; | |
} | |
return Object.assign({}, state, {todos: todos}); | |
}; | |
// Create a Redux store | |
const store = Redux.createStore(reducer); | |
const ReduxMixin = PolymerRedux(store); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment