Reactive Programming and RxJS
-
Upload
denis-gorbunov -
Category
Engineering
-
view
112 -
download
4
Transcript of Reactive Programming and RxJS
Reactive Programmingand RxJS
by Denis Gorbunov
In computing, reactive programming is a programming paradigm oriented around data
flows and the propagation of change.
wikipedia.org
Systems built as Reactive Systems are more flexible, loosely-coupled and scalable. This makes them easier to develop and amenable to change.
They are significantly more tolerant of failure and when failure does
occur they meet it with elegance rather than disaster.
Reactive Systems are highly responsive, giving users effective
interactive feedback.reactivemanifesto.org
reactivex.io
Java: RxJavaJavaScript: RxJSC#: Rx.NETC#(Unity): UniRxScala: RxScalaClojure: RxClojureC++: RxCpp
Ruby: Rx.rbPython: RxPYGroovy: RxGroovyJRuby: RxJRubyKotlin: RxKotlinSwift: RxSwiftPHP: RxPHP
reactivex.io
Java: RxJavaJavaScript: RxJSC#: Rx.NETC#(Unity): UniRxScala: RxScalaClojure: RxClojureC++: RxCpp
Ruby: Rx.rbPython: RxPYGroovy: RxGroovyJRuby: RxJRubyKotlin: RxKotlinSwift: RxSwiftPHP: RxPHP
ReactiveX is a combination of the best ideas from
the Observer pattern, the Iterator pattern, and functional programming
reactivex.io
Observable and Observer
RxJS: Operators
ReactiveX provides a collection of operators with which you can filter, select, transform, combine, and compose
Observables.
This allows for efficient execution and composition.
RxJS: Operators• buffer• bufferCount• bufferTime• bufferToggle• bufferWhen• cache• catch• combineAll• combineLates
t• concat• concatAll• concatMap• concatMapTo• create
• debounce• debounceTim
e• defaultIfEmpt
y• distinctUntilC
hanged• delay• delayWhen• do• every• empty• expand• filter• first
• forkJoin• from• fromEvent• fromPromise• groupBy• ignoreElemen
ts• interval• last• let• map• mapTo• merge• mergeAll• mergeMap
RxJS: Operators• multicast• of• partition• pluck• publish• race• range• retry• retryWhen• sample• share• single
• skip• skipUntil• skipWhile• startWith• take• takeUntil• takeWhile• throttle• throttleTime• throw• timer• toPromise
• scan• switchMap• window• windowCount• windowTime• windowToggle• windowWhen• withLatestFro
m• zip
switchMap
Subject
Subject
Subject
Subject
Subject
Hot and Cold Observables
medium.com/@benlesh
Observables are functions that tie an observer to a producer.
RxJS: Observable and Observer
Hot and Cold Observables
COLD is when your observable creates the producer
medium.com/@benlesh
Hot and Cold Observables
COLD is when your observable creates the producer
HOT is when your observable closes over the producer
medium.com/@benlesh
Hot and Cold Observables
COLD is when your observable creates the producer
HOT is when your observable closes over the producer
medium.com/@benlesh
Unsubscribe
Unsubscribe
medium.com/@benlesh
• take(n): emits N values before stopping the observable.
• takeWhile(predicate): tests the emitted values against a predicate, if it returns `false`, it will complete.
• first(): emits the first value and completes.• first(predicate): checks each value against
a predicate function, if it returns `true`, the emits that value and completes.