made with esnextbin
Last active
April 8, 2016 20:25
-
-
Save davidchase/04ec8830a64d51f87897a1e3cb086767 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>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 {iterate, fromPromise, fromEvent, multicast, sample} from 'most'; | |
const btn = fromEvent('click', document.querySelector('button')).multicast(); | |
const fetchP = () => fetch('http://reqres.in/api/users?page=2').then(resp => resp.json()); | |
const toggle = btn | |
.loop(function(msg, events){ | |
const resp = msg === 'Done' ? 'Loading' : 'Done'; | |
return {seed: resp, value: resp}; | |
}, 'Done'); | |
const promise = btn.map(fetchP).await(); | |
const sampled = function(fn, sampler, ...streams){ | |
const msampler = multicast(sampler); | |
return sample(fn, msampler, msampler, ...streams); | |
}; | |
sampled(function(){ | |
return arguments; | |
}, promise, toggle).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'); | |
var btn = (0, _most.fromEvent)('click', document.querySelector('button')).multicast(); | |
var fetchP = function fetchP() { | |
return fetch('http://reqres.in/api/users?page=2').then(function (resp) { | |
return resp.json(); | |
}); | |
}; | |
var toggle = btn.loop(function (msg, events) { | |
var resp = msg === 'Done' ? 'Loading' : 'Done'; | |
return { seed: resp, value: resp }; | |
}, 'Done'); | |
var promise = btn.map(fetchP).await(); | |
var sampled = function sampled(fn, sampler) { | |
var msampler = (0, _most.multicast)(sampler); | |
for (var _len = arguments.length, streams = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | |
streams[_key - 2] = arguments[_key]; | |
} | |
return _most.sample.apply(undefined, [fn, msampler, msampler].concat(streams)); | |
}; | |
sampled(function () { | |
return arguments; | |
}, promise, toggle).observe(console.log.bind(console)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment