Skip to content

Instantly share code, notes, and snippets.

@james-world
Created October 21, 2014 10:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james-world/ccaa345edefb9aabd76b to your computer and use it in GitHub Desktop.
Save james-world/ccaa345edefb9aabd76b to your computer and use it in GitHub Desktop.
/* Name of Gist */
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div class="container" style="padding: 10px;">
<h1>Title</h1>
<p>Body of the text</p>
<div id="here"></div>
<button class="btn btn-default" onclick="getValue()">Press Me</button>
<div id="currentValue"></div>
</div>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/rx.all.js"></script>
<script type="text/javascript">
var data = Rx.Observable.defer( function() {
return Rx.Observable.return(Math.random() * 1000).delay(5000);
}).repeat();
var cache = new Rx.ReplaySubject(1);
data.subscribe(cache);
/* log out the cache values as they arrive*/
cache.subscribe(function(x) {
console.log(x);
});
function getValue() {
cache.first().subscribe(function(x) {
$("#currentValue").text(x);
/* clear value after a second */
/* to make speed obvious */
setTimeout(function() { $("#currentValue").text(""); }, 1000);
});
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment