Skip to content

Instantly share code, notes, and snippets.

@TylorS
Last active March 11, 2016 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylorS/d76f9472373b7c6dabc1 to your computer and use it in GitHub Desktop.
Save TylorS/d76f9472373b7c6dabc1 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
</head>
<body>
<div class="container">
<button class="clicker">Click Me</button>
<button class="another">Another Clicker</button>
</div>
</body>
</html>
import {of, fromEvent} from 'most';
const log = console.log.bind(console);
const info = console.info.bind(console);
const warn = console.warn.bind(console);
const bodyStream = fromEvent('click', document.body)
.multicast();
bodyStream
.filter(event => event.target.matches('.clicker'))
.observe(x => log(x.target));
bodyStream
.filter(event => event.target.matches('.another'))
.observe(x => info(x.target));
// has error
bodyStream
.filter(event => !event.target.matches('.another') && !event.target.matches('.clicker'))
.map(event => document.querySelector(event.className))
.observe(x => info(x.target))
.catch(warn);
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"most": "0.18.0"
}
}
'use strict';
var _most = require('most');
var log = console.log.bind(console);
var info = console.info.bind(console);
var warn = console.warn.bind(console);
var bodyStream = (0, _most.fromEvent)('click', document.body).multicast();
bodyStream.filter(function (event) {
return event.target.matches('.clicker');
}).observe(function (x) {
return log(x.target);
});
bodyStream.filter(function (event) {
return event.target.matches('.another');
}).observe(function (x) {
return info(x.target);
});
// has error
bodyStream.filter(function (event) {
return !event.target.matches('.another') && !event.target.matches('.clicker');
}).map(function (event) {
return document.querySelector(event.className);
}).observe(function (x) {
return info(x.target);
}).catch(warn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment