Skip to content

Instantly share code, notes, and snippets.

@namelos
Last active March 6, 2016 05:55
Show Gist options
  • Save namelos/281aa1dc3c92ae399cc0 to your computer and use it in GitHub Desktop.
Save namelos/281aa1dc3c92ae399cc0 to your computer and use it in GitHub Desktop.
rx.js snippets
import { Observable } from 'rx'
const { fromEvent } = Observable
const $app = document.querySelector('#app')
$app.innerText = 'app'
const one = () => 1
const sum = (x, y) => x + y
fromEvent($app, 'click')
.map(one)
.startWith(100)
.scan(sum)
.subscribe(log)
import { Observable } from 'rx'
import { get } from 'axios'
const { just, fromPromise } = Observable
const log = console.log.bind(console)
const $app = document.querySelector('#app')
$app.innerText = 'app'
const url = 'http://api.github.com/users'
const mapUrl = () => url
const getUrl = url => fromPromise(get(url))
fromEvent($app, 'click')
.startWith('startup click')
.map(mapUrl)
.flatMap(getUrl)
.subscribe(log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment