RxJS
I am Hugo Cordier
CTO at Melusyn
Javascript developer
Java/Groovy developer
You can find me at:
@HugoCrd
With a lot of non
related stock photos
Slide 3
Slide 3 text
Melusyn helps film
makers to manage and
organize their
productions
We are hiring!
Drop me a line at
[email protected]
♥
Slide 4
Slide 4 text
➜ Callbacks, Promises and Rx
➜ Rx, brief introduction
➜ Use cases and demo
➜ Rx world
Slide 5
Slide 5 text
Callbacks
& Promises
This guy with an iPhone has
nothing to do with FRP. But
look at this beautiful slide!
Slide 6
Slide 6 text
Callbacks - Welcome to hell
getAsync1(function (r1, e) {
if (er) return error(e)
getAsync2(function (r2, e) {
if (er) return error(e)
getAsync3(function (r3, e) {
if (er) return error(e)
getAsync4(function (r4, e) {
doSomething(r1, r2, r3, r4)
})
})
})
})
Error handling
becomes
messy
Hard to understand
what the developer
intended to do
Slide 7
Slide 7 text
Promises - Good answer to callbacks
var promisedR1 = getAsync1()
var promisedR2 = getAsync2()
var promisedR3 = getAsync3()
Promise
.all([promisedR1,promisedR2,promisedR3])
.then(function(results) {
doSomething(results)
})
That’s neat!
But...
Slide 8
Slide 8 text
Promises - But...
You can’t use Promises to
➜ Process events (UI, Push from
server, Angular-style $watch, ...)
➜ Use time-related logic (Timeout,
Delay, Debounce, …)
➜ Compose async sources together
Slide 9
Slide 9 text
Introducing Observables
Rx
Slide 10
Slide 10 text
Rx - Observables
An Observable can :
➜ emit events (0 to ∞)
➜ emit an Error
➜ complete stream
Once an Error has been emitted, no
further events can be.
An Observable could not complete.
Slide 11
Slide 11 text
Rx - Graphic representation
Marble Diagrams
Live exemples : http://rxmarbles.com
Slide 12
Slide 12 text
Rx - Observable are asynchronous Iterables
Single return value Mutiple return values
Synchronous Object Iterables(Array | Set | Map)
Asynchronous Promise Observable
Rx - Create an Observable
// From object
Rx.Observable.just(12)
// From array
Rx.Observable.from([12,34,5,6])
// From interval
Rx.Observable.interval(100)
// From promise
Rx.Observable.fromPromise(promise)
// From DOM event
Rx.Observable.fromEvent(document.getElementById
('searchField'), 'keyup')
Slide 16
Slide 16 text
Rx - Create an Observable
// From Node.js Callback, Events, Streams
Rx.Node.fromNodeCallback(fs.stat)('file.txt')
Rx.Node.fromEvent(eventEmitter, 'eventName')
Rx.Node.fromStream(process.stdin)
Rx.Node.fromReadableStream(process.stdin)
Rx.Node.fromTransformStream(getTransformStreamSomehow())
// From Angular $watch
Rx.Observable.$watch(scope, 'search')
.flatMap(search => $http.get('api/search/'+search))
.subscribe(result => console.log(result))
Javascript :
➜ Bacon.js
➜ Kefir
➜ ELM (language)
Not javascript :
➜ Reactive-banana, Frappuccino, React4j,
ReactiveCocoa, Sodium
Other FRP libraries
Slide 23
Slide 23 text
Thanks!
Any questions?
You can find me at:
@HugoCrd
[email protected]
Did I tell you we’re hiring?
Slide 24
Slide 24 text
CREDITS
Special thanks to all the people who made and
released these awesome resources for free:
➜ Simple line icons by Mirko Monti
➜ E-commerce icons by Virgil Pana
➜ Streamline iconset by Webalys
➜ Presentation template by SlidesCarnival
➜ Photographs by Death to the Stock Photo
(license)