made with esnextbin
Last active
April 6, 2016 14:21
-
-
Save davidchase/446e72f299f2abfcb8597108742e20f2 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"/> | |
</head> | |
<body> | |
<button class="btn">Click Me</button> | |
</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 {fromEvent, fromPromise, combine, map} from 'most'; | |
console.clear(); | |
const promiseF = () => fetch('http://reqres.in/api/users?page=2').then(r => r.json()); | |
const btn = fromEvent('click', document.body) | |
.tap(console.count.bind(console)) | |
.filter(event => event.target.matches('.btn')) | |
.multicast() | |
const promiseStream = map(promiseF, btn).await().take(1); | |
combine((events, resp) => resp, btn, promiseStream).observe(console.log.bind(console)); |
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.8" | |
} | |
} |
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'); | |
console.clear(); | |
var promiseF = function promiseF() { | |
return fetch('http://reqres.in/api/users?page=2').then(function (r) { | |
return r.json(); | |
}); | |
}; | |
var btn = (0, _most.fromEvent)('click', document.body).tap(console.count.bind(console)).filter(function (event) { | |
return event.target.matches('.btn'); | |
}).multicast(); | |
var promiseStream = (0, _most.map)(promiseF, btn).await().take(1); | |
(0, _most.combine)(function (events, resp) { | |
return resp; | |
}, btn, promiseStream).observe(console.log.bind(console)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment