Skip to content

Commit

Permalink
Merge d897971 into 864fbab
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnyroeller committed Jun 13, 2017
2 parents 864fbab + d897971 commit bd5285d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 51 deletions.
4 changes: 3 additions & 1 deletion bower.json
Expand Up @@ -30,6 +30,8 @@
"polymer": "^2.0.0"
},
"devDependencies": {
"web-component-tester": "^6.0.0"
"web-component-tester": "^6.0.0",
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^2.0.0",
"vaadin-combo-box": "^2.0.0-alpha4"
}
}
100 changes: 50 additions & 50 deletions demo/ready-state.html
Expand Up @@ -22,28 +22,6 @@
<h3>Polymer Redux, Ready State</h3>
<demo-snippet>
<template>
<!-- redux setup -->
<script>
const initialState = {
friends: ['Adam', 'Beth', 'Carl', 'Denise'],
chosenFriend: 'Beth',
};
const reducer = (state, action) => {
if (!state) return initialState;

switch (action.type) {
case 'CHOOSE_FRIEND':
return Object.assign({}, state, {
chosenFriend: action.friend
});
}

return state;
}
const store = Redux.createStore(reducer);
const ReduxBehavior = PolymerRedux(store);
</script>

<!-- friends list module -->
<dom-module id="friend-picker">
<template>
Expand All @@ -57,38 +35,60 @@ <h3>Choose a Friend:</h3>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'friend-picker',
behaviors: [ ReduxBehavior ],
properties: {
list: {
type: Array,
statePath: 'friends'
},
friend: {
type: String,
statePath: 'chosenFriend'
}
},
actions: {
chooseFriend: function(friend) {
return {
type: 'CHOOSE_FRIEND',
friend: friend
};
}
},
onFriendChange: function() {
this.dispatch('chooseFriend', this.$['friend-list'].value);
}
});
</script>

<!-- demo -->
<friend-picker></friend-picker>
</template>
</demo-snippet>
<script>
// redux setup
const initialState = {
friends: ['Adam', 'Beth', 'Carl', 'Denise'],
chosenFriend: 'Beth',
};
const reducer = (state, action) => {
if (!state) return initialState;

switch (action.type) {
case 'CHOOSE_FRIEND':
return Object.assign({}, state, {
chosenFriend: action.friend
});
}

return state;
}
const store = Redux.createStore(
reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
const ReduxBehavior = PolymerRedux(store);

Polymer({
is: 'friend-picker',
behaviors: [ ReduxBehavior ],
properties: {
list: {
type: Array,
statePath: 'friends'
},
friend: {
type: String,
statePath: 'chosenFriend'
}
},
actions: {
chooseFriend: function(friend) {
return {
type: 'CHOOSE_FRIEND',
friend: friend
};
}
},
onFriendChange: function() {
this.dispatch('chooseFriend', this.$['friend-list'].value);
}
});
</script>
</div>
</body>
</html>

0 comments on commit bd5285d

Please sign in to comment.