Skip to content

Instantly share code, notes, and snippets.

@tomraithel
Created January 21, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomraithel/385130ada84d13ab64e1 to your computer and use it in GitHub Desktop.
Save tomraithel/385130ada84d13ab64e1 to your computer and use it in GitHub Desktop.
Cycle.js
import Cycle from '@cycle/core';
import {div, label, input, h1, button, p, makeDOMDriver} from '@cycle/dom';
const _ = require('lodash');
const {Observable} = require('rx');
function f1(sources) {
const sinks = {
DOM: sources.DOM.select('.field').events('input')
.map(ev => ev.target.value)
.startWith('12')
.map(name =>
div([
label('Name:'),
div('Tests'),
input('.field', {attributes: {type: 'text'}}),
h1('Hello2 ' + name)
])
)
};
return sinks;
}
function f2(sources) {
const decrement$ = sources.DOM
.select('.decrement').events('click').map(ev => -1);
const increment$ = sources.DOM
.select('.increment').events('click').map(ev => +1);
const action$ = Observable.merge(decrement$, increment$);
const count$ = action$.startWith(0).scan((x,y) => x+y);
const vtree$ = count$.map(count =>
div([
button('.decrement', 'Decrement'),
button('.increment', 'Increment'),
p('Counter: ' + count)
])
);
return { DOM: vtree$ };
}
let main = f2;
const sources = { DOM: makeDOMDriver('.app') }
//Cycle.run(main, );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment