Skip to content

Instantly share code, notes, and snippets.

@jyasskin
Created September 3, 2014 23:41
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 jyasskin/f88fe1230fcc53a36285 to your computer and use it in GitHub Desktop.
Save jyasskin/f88fe1230fcc53a36285 to your computer and use it in GitHub Desktop.
<step-button>, a button that can vend promises that resolve when it's clicked
<!-- Call wait() on this button to return a Promise that resolves when the button is clicked. -->
<polymer-element name='step-button'>
<template><button on-click="{{step}}" disabled?="{{!_resolve}}">Step</button></template>
<script>
(function() {
Polymer('step-button', {
wait: function() {
var self = this;
return new Promise(function(resolve, reject) {
if (self._resolve) {
reject('Schedule one step at a time.');
} else {
self._resolve = resolve;
}
});
},
step: function() {
this._resolve();
this._resolve = null;
},
});
})();
</script>
</polymer-element>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment