Skip to content

Instantly share code, notes, and snippets.

@Hypnosphi
Last active December 31, 2016 14:56
Show Gist options
  • Save Hypnosphi/0765658af0d20a82ff8486df4cdab607 to your computer and use it in GitHub Desktop.
Save Hypnosphi/0765658af0d20a82ff8486df4cdab607 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<div id="app"></div>
</body>
</html>
import xs from 'xstream';
import {run} from '@cycle/xstream-run';
import {makeHTTPDriver} from '@cycle/http';
import {makeDOMDriver, div} from '@cycle/dom';
function main(source) {
const response$ = source.HTTP.select()
.flatten()
const accumulatedResponse$ = response$.fold((acc, res) => acc.concat(res), []);
const request$ = xs.periodic(2000)
.mapTo({ url: 'https://api.github.com', method: 'GET' });
return {
DOM: accumulatedResponse$.map(responses =>
div(responses.map(res =>
div([res.body.emails_url])
))
),
HTTP: request$
};
}
run(main, {
DOM: makeDOMDriver('#app'),
HTTP: makeHTTPDriver()
});
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"xstream": "9.0.0",
"@cycle/xstream-run": "4.2.0",
"@cycle/http": "11.2.0",
"@cycle/dom": "14.3.0"
}
}
'use strict';
var _xstream = require('xstream');
var _xstream2 = _interopRequireDefault(_xstream);
var _xstreamRun = require('@cycle/xstream-run');
var _http = require('@cycle/http');
var _dom = require('@cycle/dom');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function main(source) {
var response$ = source.HTTP.select().flatten();
var accumulatedResponse$ = response$.fold(function (acc, res) {
return acc.concat(res);
}, []);
var request$ = _xstream2.default.periodic(2000).mapTo({ url: 'https://api.github.com', method: 'GET' });
return {
DOM: accumulatedResponse$.map(function (responses) {
return (0, _dom.div)(responses.map(function (res) {
return (0, _dom.div)([res.body.emails_url]);
}));
}),
HTTP: request$
};
}
(0, _xstreamRun.run)(main, {
DOM: (0, _dom.makeDOMDriver)('#app'),
HTTP: (0, _http.makeHTTPDriver)()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment