made with esnextbin
Created
December 2, 2016 10:24
-
-
Save geovanisouza92/6b5b3b9f510b8d360568862586ade42d 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 class="app"></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/xstream-run' | |
| import {makeDOMDriver, a} from '@cycle/dom' | |
| import isolate from '@cycle/isolate' | |
| import xs from 'xstream' | |
| import dropRepeats from 'xstream/extra/dropRepeats' | |
| function link (sources) { | |
| console.log(sources.DOM) | |
| const click$ = sources.DOM | |
| .select('a').events('click') | |
| const data$ = xs.combine(sources.props$, click$) | |
| .map(([props, _]) => props.data) | |
| const vtree$ = sources.props$ | |
| .map(props => | |
| a(props.text) | |
| ) | |
| const sinks = { | |
| DOM: vtree$.debug('DOM'), | |
| data$: data$.debug('data$') | |
| } | |
| return sinks | |
| } | |
| const Link = sources => isolate(link)(sources) | |
| function main (sources) { | |
| const props$ = xs.of({text: 'one', data: 'two'}) | |
| .compose(dropRepeats()) | |
| /* | |
| const link = Link({...sources, props$}) | |
| const vtree$ = link.DOM | |
| const log$ = link.data$ | |
| //*/ | |
| // /* | |
| const link$ = props$ | |
| .debug('props$') | |
| .map(props => | |
| Link({...sources, props$: xs.of(props)}) | |
| ) | |
| .debug('link$') | |
| .remember() | |
| const log$ = link$ | |
| .map(link => link.data$) | |
| .flatten() | |
| const vtree$ = link$ | |
| .map(link => link.DOM) | |
| .flatten() | |
| //*/ | |
| const sinks = { | |
| log: log$, | |
| DOM: vtree$ | |
| } | |
| return sinks | |
| } | |
| run(main, { | |
| DOM: makeDOMDriver('.app'), | |
| log: (msg$) => { | |
| msg$.addListener({ | |
| next (v) { | |
| console.log(v) | |
| } | |
| }) | |
| } | |
| }) |
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/xstream-run": "4.0.0", | |
| "@cycle/dom": "14.1.0", | |
| "@cycle/isolate": "1.4.0", | |
| "xstream": "9.0.0", | |
| "babel-runtime": "6.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 _extends2 = require('babel-runtime/helpers/extends'); | |
| var _extends3 = _interopRequireDefault(_extends2); | |
| var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | |
| var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | |
| var _xstreamRun = require('@cycle/xstream-run'); | |
| var _dom = require('@cycle/dom'); | |
| var _isolate = require('@cycle/isolate'); | |
| var _isolate2 = _interopRequireDefault(_isolate); | |
| var _xstream = require('xstream'); | |
| var _xstream2 = _interopRequireDefault(_xstream); | |
| var _dropRepeats = require('xstream/extra/dropRepeats'); | |
| var _dropRepeats2 = _interopRequireDefault(_dropRepeats); | |
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
| function link(sources) { | |
| console.log(sources.DOM); | |
| var click$ = sources.DOM.select('a').events('click'); | |
| var data$ = _xstream2.default.combine(sources.props$, click$).map(function (_ref) { | |
| var _ref2 = (0, _slicedToArray3.default)(_ref, 2); | |
| var props = _ref2[0]; | |
| var _ = _ref2[1]; | |
| return props.data; | |
| }); | |
| var vtree$ = sources.props$.map(function (props) { | |
| return (0, _dom.a)(props.text); | |
| }); | |
| var sinks = { | |
| DOM: vtree$.debug('DOM'), | |
| data$: data$.debug('data$') | |
| }; | |
| return sinks; | |
| } | |
| var Link = function Link(sources) { | |
| return (0, _isolate2.default)(link)(sources); | |
| }; | |
| function main(sources) { | |
| var props$ = _xstream2.default.of({ text: 'one', data: 'two' }).compose((0, _dropRepeats2.default)()); | |
| /* | |
| const link = Link({...sources, props$}) | |
| const vtree$ = link.DOM | |
| const log$ = link.data$ | |
| //*/ | |
| // /* | |
| var link$ = props$.debug('props$').map(function (props) { | |
| return Link((0, _extends3.default)({}, sources, { props$: _xstream2.default.of(props) })); | |
| }).debug('link$').remember(); | |
| var log$ = link$.map(function (link) { | |
| return link.data$; | |
| }).flatten(); | |
| var vtree$ = link$.map(function (link) { | |
| return link.DOM; | |
| }).flatten(); | |
| //*/ | |
| var sinks = { | |
| log: log$, | |
| DOM: vtree$ | |
| }; | |
| return sinks; | |
| } | |
| (0, _xstreamRun.run)(main, { | |
| DOM: (0, _dom.makeDOMDriver)('.app'), | |
| log: function log(msg$) { | |
| msg$.addListener({ | |
| next: function next(v) { | |
| console.log(v); | |
| } | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment