made with esnextbin
Created
March 11, 2016 13:47
-
-
Save davidchase/00e261a0771c4fa55f3d to your computer and use it in GitHub Desktop.
esnextbin sketch
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>ESNextbin Sketch</title> | |
</head> | |
<body> | |
<div class="container"> | |
<button class="clicker">Click Me</button> | |
<button class="another">Another Clicker</button> | |
</div> | |
</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
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); | |
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); |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"most": "0.18.0" | |
} | |
} |
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
'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); | |
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