Created
July 18, 2016 16:25
-
-
Save rodmcnew/7639702a41751b769180474b639ec440 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<!-- @TODO uso more official polymer urls than cdn.rawgit.com/download--> | |
<script src="https://cdn.rawgit.com/download/polymer-cdn/1.5.0/lib/webcomponentsjs/webcomponents-lite.min.js"></script> | |
<link rel="import" href="https://cdn.rawgit.com/download/polymer-cdn/1.5.0/lib/iron-ajax/iron-ajax.html"> | |
<style> | |
h1 { | |
text-align: center; | |
font-size: 50px; | |
} | |
body div { | |
text-align: center; | |
} | |
</style> | |
<dom-module id="release-watcher"> | |
<template> | |
<iron-ajax | |
id="releaseAjax" | |
url="/release.json" | |
handle-as="json" | |
on-response="handleResponse" | |
last-response="{{release}}" | |
debounce-duration="300"> | |
</iron-ajax> | |
<template is="dom-if" if="{{changed}}"> | |
<h1 style="color: orangered"> | |
Version change detected! | |
</h1> | |
</template> | |
<template is="dom-if" if="{{!changed}}"> | |
<h1> | |
Watching for a version change... | |
</h1> | |
</template> | |
<div> | |
<p>Version: <span>{{release.version}}</span></p> | |
<p>Last Release: <span>{{release.date.date}}</span></p> | |
<p>Times Checked: <span>{{timesChecked}}</span></p> | |
</div> | |
</template> | |
<script> | |
Polymer({ | |
is: "release-watcher", | |
ready: function () { | |
this.timesChecked = 0; | |
this.changed = false; | |
this.doRequest(); | |
var self = this; | |
setInterval(function () { | |
self.doRequest(); | |
}, 2000); | |
}, | |
doRequest: function () { | |
this.$.releaseAjax.params = {"cacheBreaker": Math.random()}; | |
this.$.releaseAjax.generateRequest(); | |
}, | |
handleResponse: function () { | |
this.timesChecked++; | |
if (this.previousRelease && this.release.version != this.previousRelease.version) { | |
this.changed = true; | |
} | |
this.previousRelease = this.release; | |
} | |
}); | |
</script> | |
</dom-module> | |
</head> | |
<body> | |
<release-watcher></release-watcher> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment