Created
May 28, 2016 22:43
-
-
Save anonymous/56b3fb5353f2bcdbfb976314c6680abb to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/funaqocoso
This file contains hidden or 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> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<script src="https://rawgit.com/baconjs/bacon.js/master/dist/Bacon.js"></script> | |
<style id="jsbin-css"> | |
button, textarea { | |
display: block; | |
margin: 10px; | |
width: 200px | |
} | |
</style> | |
</head> | |
<body> | |
<button id="enable">Enable</button> | |
<button id="disable">Disable</button> | |
<textarea id="target"></textarea> | |
<script id="jsbin-javascript"> | |
function getRandomIntInclusive(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
var enableClicks = $("#enable").asEventStream("click"); | |
var disableClicks = $("#disable").asEventStream("click"); | |
// Use .map to create a stream with more sensible values than jquery events | |
var enableStream = enableClicks.map(function(x) {return getRandomIntInclusive(1,10);}); | |
var disableStream = disableClicks.map(function(x) {return getRandomIntInclusive(1000,10000);}); | |
// Use .merge to join the two streams together | |
var combinedStream = enableStream.merge(disableStream); | |
// Use .onValue to enable or disable the | |
// textarea | |
combinedStream.onValue(function(x) { | |
console.log("number from result stream:", x); | |
if (x>10) | |
$("#target").prop( "disabled", true ); | |
}); | |
</script> | |
<script id="jsbin-source-css" type="text/css">button, textarea { | |
display: block; | |
margin: 10px; | |
width: 200px | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function getRandomIntInclusive(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
var enableClicks = $("#enable").asEventStream("click"); | |
var disableClicks = $("#disable").asEventStream("click"); | |
// Use .map to create a stream with more sensible values than jquery events | |
var enableStream = enableClicks.map(function(x) {return getRandomIntInclusive(1,10);}); | |
var disableStream = disableClicks.map(function(x) {return getRandomIntInclusive(1000,10000);}); | |
// Use .merge to join the two streams together | |
var combinedStream = enableStream.merge(disableStream); | |
// Use .onValue to enable or disable the | |
// textarea | |
combinedStream.onValue(function(x) { | |
console.log("number from result stream:", x); | |
if (x>10) | |
$("#target").prop( "disabled", true ); | |
});</script></body> | |
</html> |
This file contains hidden or 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
button, textarea { | |
display: block; | |
margin: 10px; | |
width: 200px | |
} |
This file contains hidden or 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
function getRandomIntInclusive(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
var enableClicks = $("#enable").asEventStream("click"); | |
var disableClicks = $("#disable").asEventStream("click"); | |
// Use .map to create a stream with more sensible values than jquery events | |
var enableStream = enableClicks.map(function(x) {return getRandomIntInclusive(1,10);}); | |
var disableStream = disableClicks.map(function(x) {return getRandomIntInclusive(1000,10000);}); | |
// Use .merge to join the two streams together | |
var combinedStream = enableStream.merge(disableStream); | |
// Use .onValue to enable or disable the | |
// textarea | |
combinedStream.onValue(function(x) { | |
console.log("number from result stream:", x); | |
if (x>10) | |
$("#target").prop( "disabled", true ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment