made with esnextbin
Created
May 19, 2017 02:54
-
-
Save chenxeed/a86be2c6bafa976606826d43d43e1409 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> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
<div id="app-container"></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 {run} from '@cycle/run' | |
import xs from 'xstream'; | |
import { makeHTTPDriver } from '@cycle/http'; | |
function main(sources) { | |
const respPost$ = sources.HTTP.select('post').debug('post'); | |
const respUser$ = sources.HTTP.select('user').debug('user'); | |
const requestPost$ = xs.of({ | |
url: 'https://jsonplaceholder.typicode.com/posts/1', | |
method: 'GET', | |
category: 'post' | |
}); | |
const requestUser$ = respPost$.mapTo({ | |
url: 'https://jsonplaceholder.typicode.com/users/1', | |
method: 'GET', | |
category: 'user' | |
}); | |
const request$ = xs.merge(requestPost$, requestUser$); | |
const response$ = xs.merge(respPost$, respUser$); | |
return { | |
HTTP : request$, | |
debug : response$ | |
} | |
} | |
run(main, { | |
HTTP: makeHTTPDriver(), | |
debug : console.log | |
}) |
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": { | |
"@cycle/run": "3.0.0", | |
"xstream": "10.2.0", | |
"@cycle/http": "12.0.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 _run = require('@cycle/run'); | |
var _xstream = require('xstream'); | |
var _xstream2 = _interopRequireDefault(_xstream); | |
var _http = require('@cycle/http'); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function main(sources) { | |
var respPost$ = sources.HTTP.select('post').debug('post'); | |
var respUser$ = sources.HTTP.select('user').debug('user'); | |
var requestPost$ = _xstream2.default.of({ | |
url: 'https://jsonplaceholder.typicode.com/posts/1', | |
method: 'GET', | |
category: 'post' | |
}); | |
var requestUser$ = respPost$.mapTo({ | |
url: 'https://jsonplaceholder.typicode.com/users/1', | |
method: 'GET', | |
category: 'user' | |
}); | |
var request$ = _xstream2.default.merge(requestPost$, requestUser$); | |
var response$ = _xstream2.default.merge(respPost$, respUser$); | |
return { | |
HTTP: request$, | |
debug: response$ | |
}; | |
} | |
(0, _run.run)(main, { | |
HTTP: (0, _http.makeHTTPDriver)(), | |
debug: console.log | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment