Published
Edited
Oct 2, 2019
Insert cell
Insert cell
info[0]
Insert cell
import {rx, obs, spy} from "@lbovet/rx-tools"
Insert cell
rx
Insert cell
rx.Observable === obs
Insert cell
obs.of(1, 2, 3, 4, 5)
Insert cell
value
Insert cell
obs.of(1,2,3,4).subscribe(set)
Insert cell
obs.of(1, 2, 3, 4, 5).values()
Insert cell
obs.of(1, 2, 3, 4, 5)
.filter(x => x % 2)
.map(x => 2*x)
.values()
Insert cell
Insert cell
obs.interval(1000).value()
Insert cell
obs.fromEvent(document, 'click').pluck('x').value()
Insert cell
obs.interval(1000).take(10).values()
Insert cell
obs.interval(1000).take(10).view()
Insert cell
obs
.interval(1000)
.map(util.colored)
.take(10)
.view()
Insert cell
obs.of(3).map(util.colored).value()
Insert cell
obs.of("cyan", "#f00", "hsl(108,80%,80%)").view({size:40})
Insert cell
Insert cell
obs
.fromPromise($.get(sample[0]))
.map(res => res.data.first_name)
.value()
Insert cell
get$ = (url) => obs.fromPromise($.get(url))
Insert cell
get$(sample[1])
.map(res => util.img(res.data.avatar))
.value()
Insert cell
info[1]
Insert cell
Insert cell
obs
.interval(1000)
.map( i => sample[i % 2] )
.do(spy(1).set)
.flatMap( get$ )
.map( res => res.data.first_name.length )
.map( util.colored )
.take(10)
.view()
Insert cell
spy(1).value()
Insert cell
obs.prototype.flatMap == obs.prototype.mergeMap
Insert cell
md`${sample[2]}`
Insert cell
get$(`${sample[2]}/users`).value()
Insert cell
Insert cell
allCommentersToLastPost =
(username) =>
obs.of(null)
.map(any => `${sample[2]}/users`)
.flatMap( get$ )
.flatMap( obs.from )
.filter( user => user.username == username )
.map( user => `${sample[2]}/posts?userId=${user.id}` )
.flatMap( get$ )
.flatMap( obs.from )
.last()
.map( post => `${sample[2]}/comments?postId=${post.id}` )
.flatMap( get$ )
.flatMap( obs.from )
.pluck('email')
Insert cell
allCommentersToLastPost('Samantha').values()
Insert cell
Insert cell
urls = sample[3]
Insert cell
urls.posts({id:4})
Insert cell
load =
computeUrl =>
obj => obs.of(obj)
.map(computeUrl)
.flatMap(get$)
.flatMap(obs.from)
Insert cell
firstCommentersToAllPosts =
(username) =>
obs.of(1)
.flatMap( load(urls.users) )
.filter( user => user.username == username )
.flatMap( load(urls.posts) )
.flatMap( util.compose(first, load(urls.comments)) )
.pluck('email')
Insert cell
info[3]
Insert cell
first = x => x.first()
Insert cell
firstCommentersToAllPosts('Samantha').values()
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more