Skip to content

Instantly share code, notes, and snippets.

@JaySunSyn
Last active January 17, 2018 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaySunSyn/f133253476257baa652269ca557daa67 to your computer and use it in GitHub Desktop.
Save JaySunSyn/f133253476257baa652269ca557daa67 to your computer and use it in GitHub Desktop.
Redux Polymer Todo Tutorial Step-1
<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