Last active
March 17, 2016 22:53
-
-
Save milankinen/7ab1aab182bc28bd9567 to your computer and use it in GitHub Desktop.
TSERS "cyclish"
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 {Observable as O} from "rx" | |
import makeReactDOM from "@tsers/react" | |
import tsersRun from "./tsersRun" | |
function main({DOM}) { | |
let {h} = DOM | |
let action$ = O.merge( | |
DOM.select('.decrement').events('click').map(ev => -1), | |
DOM.select('.increment').events('click').map(ev => +1) | |
); | |
let count$ = action$.startWith(0).scan((x, y) => x + y); | |
return { | |
DOM: count$.map(count => | |
h('div', [ | |
h('button.decrement', 'Decrement'), | |
h('button.increment', 'Increment'), | |
h('p', 'Counter: ' + count) | |
]) | |
) | |
}; | |
} | |
tsersRun(main, { | |
DOM: makeReactDOM("#app") | |
}) |
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 TSERS from "@tsers/core" | |
export default function tsersRun(main, drivers) { | |
const [T, S, E] /* R S */ = TSERS(drivers) | |
const { run: run_, extract, DOM, compose } = T | |
const main_ = in$ => { | |
const dom$ = extract(in$, "DOM$") | |
const sources = { DOM: {...DOM, select: selector => ({events: type => DOM.events(dom$, selector, type)})} } | |
const out = main(sources) | |
const DOM$ = DOM.prepare(out.DOM) | |
return [compose({...out, DOM: DOM$}), compose({DOM$})] | |
} | |
return E(run_(S, main_)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment