Created
October 19, 2014 02:17
-
-
Save thetrav/b1d27db3e8820146204c to your computer and use it in GitHub Desktop.
Bacon Dispatch?
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> | |
<title>test eventTicks</title> | |
<script src="js/lib/zepto-1.1.4.js"></script> | |
<script src="js/lib/bacon-0.7.12.js"></script> | |
<script> | |
$(function() { | |
var ticks = new Bacon.Bus(); | |
ticks.plug($(".ticker").asEventStream("click", function() { | |
return {tick: 1}; | |
})); | |
var tocks = new Bacon.Bus(); | |
tocks.plug($(".tocker").asEventStream("click", function() { | |
return {tock: 1}; | |
})); | |
var tickProp = ticks.scan(0, function(m, e) { | |
return m + e.tick; | |
}); | |
tickProp.assign($('.ticks'), "text"); | |
var tockProp = tocks.scan(0, function(m, e) { | |
return m + e.tock; | |
}); | |
tockProp.assign($('.tocks'), "text"); | |
var tickTock = Bacon.combineWith(function(tickCount, tockCount) { | |
if(tickCount == 2) { | |
ticks.push({tick: -2}); | |
tocks.push({tock: 1}); | |
} | |
return {ticks: tickCount, tocks: tockCount}; | |
}, tickProp, tockProp); | |
tickTock.onValue(function(e) { | |
$(".tickTock").text(JSON.stringify(e)); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="ticks"></div> | |
<button class="ticker">tick</button> | |
<div class="tocks"></div> | |
<button class="tocker">tock</button> | |
<div class="tickTock"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment