Created
October 21, 2014 10:49
-
-
Save james-world/ccaa345edefb9aabd76b 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
/* Name of Gist */ |
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
<!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