Skip to content

Instantly share code, notes, and snippets.

@milankinen

milankinen/main.js

Last active Mar 17, 2016
Embed
What would you like to do?
TSERS "cyclish"
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")
})
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