-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from tur-nr/fixing-ready-state
- Loading branch information
Showing
3 changed files
with
193 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Polymer Redux, Ready State</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes"> | ||
<script src="../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../../node_modules/redux/dist/redux.js"></script> | ||
|
||
<link rel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html"> | ||
<link rel="import" href="../../iron-demo-helpers/demo-snippet.html"> | ||
<link rel="import" href="../../vaadin-combo-box/vaadin-combo-box.html"> | ||
|
||
<link rel="import" href="../polymer-redux.html"> | ||
|
||
<style is="custom-style" include="demo-pages-shared-styles"> | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="vertical-section-container"> | ||
<h3>Polymer Redux, Ready State</h3> | ||
<demo-snippet> | ||
<template> | ||
<!-- redux setup --> | ||
<script> | ||
const initialState = { | ||
friends: ['Adam', 'Beth', 'Carl', 'Denise'], | ||
choosenFriend: 'Beth', | ||
}; | ||
const reducer = (state, action) => { | ||
if (!state) return initialState; | ||
|
||
switch (action.type) { | ||
case 'CHOOSE_FRIEND': | ||
return Object.assign({}, state, { | ||
chooseFriend: action.friend | ||
}); | ||
} | ||
|
||
return state; | ||
} | ||
const store = Redux.createStore(reducer); | ||
const ReduxBehavior = PolymerRedux(store); | ||
</script> | ||
|
||
<!-- friends list module --> | ||
<dom-module id="friend-picker"> | ||
<template> | ||
<h3>Choose a Friend:</h3> | ||
<vaadin-combo-box id="friend-list" | ||
items="[[list]]" | ||
on-change="onFriendChange"> | ||
</vaadin-combo-box> | ||
<template is="dom-if" if="[[friend]]"> | ||
<p>You choose: [[friend]].</p> | ||
</template> | ||
</template> | ||
</dom-module> | ||
<script> | ||
Polymer({ | ||
is: 'friend-picker', | ||
behaviors: [ ReduxBehavior ], | ||
properties: { | ||
list: { | ||
type: Array, | ||
statePath: 'friends' | ||
}, | ||
friend: { | ||
type: String, | ||
statePath: 'chooseFriend' | ||
} | ||
}, | ||
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> | ||
</div> | ||
</body> | ||
</html> |
This file contains 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
This file contains 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