Last active
March 6, 2016 05:55
-
-
Save namelos/281aa1dc3c92ae399cc0 to your computer and use it in GitHub Desktop.
rx.js snippets
This file contains hidden or 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 } 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) |
This file contains hidden or 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 } 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