Skip to content

Instantly share code, notes, and snippets.

Created February 14, 2016 19:14
Show Gist options
  • Save anonymous/4c101fb4f38d49d9e5a6 to your computer and use it in GitHub Desktop.
Save anonymous/4c101fb4f38d49d9e5a6 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/ravalo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/2.3.22/rx.all.js"></script>
<style id="jsbin-css">
body {
font-family: sans-serif;
padding: 10px;
}
.button {
background: #EcEcEc;
padding: 5px;
text-decoration: none;
color: black;
border: 1px solid darkgray;
}
h4 {
font-weight: bold;
display: inline-block;
margin-left: 20px;
}
.header {
/*background: #ECECEC;
*/padding: 5px;
}
</style>
</head>
<body>
<div class="header">
<a href="#" class="button">BUTTON</a><h4>-</h4>
</div>
<script id="jsbin-javascript">
'use strict';
var button = document.querySelector('.button');
var label = document.querySelector('h4');
var clickStream = Rx.Observable.fromEvent(button, 'click');
var doubleClickStream = clickStream.buffer(function () {
return clickStream.throttle(250);
}).map(function (arr) {
return arr.length;
}).filter(function (len) {
return len === 2;
});
doubleClickStream.subscribe(function (event) {
label.textContent = 'double click';
});
doubleClickStream.throttle(1000).subscribe(function (suggestion) {
label.textContent = '-';
});
</script>
<script id="jsbin-source-css" type="text/css">body {
font-family: sans-serif;
padding: 10px;
}
.button {
background: #EcEcEc;
padding: 5px;
text-decoration: none;
color: black;
border: 1px solid darkgray;
}
h4 {
font-weight: bold;
display: inline-block;
margin-left: 20px;
}
.header {
/*background: #ECECEC;
*/padding: 5px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var button = document.querySelector('.button');
var label = document.querySelector('h4');
var clickStream = Rx.Observable.fromEvent(button, 'click');
var doubleClickStream = clickStream
.buffer(() => clickStream.throttle(250))
.map(arr => arr.length)
.filter(len => len === 2);
doubleClickStream.subscribe(event => {
label.textContent = 'double click';
});
doubleClickStream
.throttle(1000)
.subscribe(suggestion => {
label.textContent = '-';
});</script></body>
</html>
body {
font-family: sans-serif;
padding: 10px;
}
.button {
background: #EcEcEc;
padding: 5px;
text-decoration: none;
color: black;
border: 1px solid darkgray;
}
h4 {
font-weight: bold;
display: inline-block;
margin-left: 20px;
}
.header {
/*background: #ECECEC;
*/padding: 5px;
}
'use strict';
var button = document.querySelector('.button');
var label = document.querySelector('h4');
var clickStream = Rx.Observable.fromEvent(button, 'click');
var doubleClickStream = clickStream.buffer(function () {
return clickStream.throttle(250);
}).map(function (arr) {
return arr.length;
}).filter(function (len) {
return len === 2;
});
doubleClickStream.subscribe(function (event) {
label.textContent = 'double click';
});
doubleClickStream.throttle(1000).subscribe(function (suggestion) {
label.textContent = '-';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment