Created
January 21, 2016 15:15
-
-
Save tomraithel/385130ada84d13ab64e1 to your computer and use it in GitHub Desktop.
Cycle.js
This file contains 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 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