Skip to content

Instantly share code, notes, and snippets.

@namelos
Last active March 27, 2016 09:23
Show Gist options
  • Select an option

  • Save namelos/95e14f8439d930d90ad4 to your computer and use it in GitHub Desktop.

Select an option

Save namelos/95e14f8439d930d90ad4 to your computer and use it in GitHub Desktop.
import { Observable, Subject } from 'rx'
const { timer, fromEvent } = Observable
/* --- logic --- */
const main = DOM =>
DOM.startWith(null)
.flatMapLatest(
() => timer(0, 100).map(
i => `seconds elapsed ${i}`))
/* --- effects --- */
const DOM = text$ => {
text$.subscribe(text =>
document.querySelector('#app').textContent = text)
return fromEvent(document, 'click')
}
/* --- binding --- */
const run = (main, driver) => {
const proxy = new Subject()
driver(main(proxy))
.subscribe(proxy::proxy.onNext)
}
/* --- run --- */
run(main, DOM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment