reactive programming and rxjs

55
Reactive Programming and RxJS by Denis Gorbunov

Upload: denis-gorbunov

Post on 13-Jan-2017

112 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Reactive Programming and RxJS

Reactive Programmingand RxJS

by Denis Gorbunov

Page 2: Reactive Programming and RxJS

In computing, reactive programming is a programming paradigm oriented around data

flows and the propagation of change.

wikipedia.org

Page 3: Reactive Programming and RxJS

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

Page 4: Reactive Programming and RxJS
Page 5: Reactive Programming and RxJS
Page 6: Reactive Programming and RxJS
Page 7: Reactive Programming and RxJS
Page 8: Reactive Programming and RxJS
Page 9: Reactive Programming and RxJS
Page 10: Reactive Programming and RxJS
Page 11: Reactive Programming and RxJS
Page 12: Reactive Programming and RxJS
Page 13: Reactive Programming and RxJS

reactivex.io

Java: RxJavaJavaScript: RxJSC#: Rx.NETC#(Unity): UniRxScala: RxScalaClojure: RxClojureC++: RxCpp

Ruby: Rx.rbPython: RxPYGroovy: RxGroovyJRuby: RxJRubyKotlin: RxKotlinSwift: RxSwiftPHP: RxPHP

Page 14: Reactive Programming and RxJS

reactivex.io

Java: RxJavaJavaScript: RxJSC#: Rx.NETC#(Unity): UniRxScala: RxScalaClojure: RxClojureC++: RxCpp

Ruby: Rx.rbPython: RxPYGroovy: RxGroovyJRuby: RxJRubyKotlin: RxKotlinSwift: RxSwiftPHP: RxPHP

Page 15: Reactive Programming and RxJS

ReactiveX is a combination of the best ideas from

the Observer pattern, the Iterator pattern, and functional programming

reactivex.io

Page 16: Reactive Programming and RxJS

Observable and Observer

Page 17: Reactive Programming and RxJS
Page 18: Reactive Programming and RxJS
Page 19: Reactive Programming and RxJS
Page 20: Reactive Programming and RxJS
Page 21: Reactive Programming and RxJS
Page 22: Reactive Programming and RxJS

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.

Page 23: Reactive Programming and RxJS

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

Page 24: Reactive Programming and RxJS

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

Page 25: Reactive Programming and RxJS

map

rxmarbles.com

Page 26: Reactive Programming and RxJS
Page 27: Reactive Programming and RxJS

switchMap

Page 28: Reactive Programming and RxJS
Page 29: Reactive Programming and RxJS
Page 30: Reactive Programming and RxJS

combineLatest

rxmarbles.com

Page 31: Reactive Programming and RxJS
Page 32: Reactive Programming and RxJS

debounce

rxmarbles.com

Page 33: Reactive Programming and RxJS
Page 34: Reactive Programming and RxJS

filter

rxmarbles.com

Page 35: Reactive Programming and RxJS
Page 36: Reactive Programming and RxJS
Page 37: Reactive Programming and RxJS

find

rxmarbles.com

Page 38: Reactive Programming and RxJS

reduce

rxmarbles.com

Page 39: Reactive Programming and RxJS

scan

rxmarbles.com

Page 40: Reactive Programming and RxJS

takeUntil

rxmarbles.com

Page 41: Reactive Programming and RxJS

merge

rxmarbles.com

Page 42: Reactive Programming and RxJS

distinct

rxmarbles.com

Page 43: Reactive Programming and RxJS

distinctUntilChanged

rxmarbles.com

Page 44: Reactive Programming and RxJS

Subject

Page 45: Reactive Programming and RxJS

Subject

Page 46: Reactive Programming and RxJS

Subject

Page 47: Reactive Programming and RxJS

Subject

Page 48: Reactive Programming and RxJS

Subject

Page 49: Reactive Programming and RxJS

Hot and Cold Observables

medium.com/@benlesh

Observables are functions that tie an observer to a producer.

Page 50: Reactive Programming and RxJS

RxJS: Observable and Observer

Page 51: Reactive Programming and RxJS

Hot and Cold Observables

COLD is when your observable creates the producer

medium.com/@benlesh

Page 52: Reactive Programming and RxJS

Hot and Cold Observables

COLD is when your observable creates the producer

HOT is when your observable closes over the producer

medium.com/@benlesh

Page 53: Reactive Programming and RxJS

Hot and Cold Observables

COLD is when your observable creates the producer

HOT is when your observable closes over the producer

medium.com/@benlesh

Page 54: Reactive Programming and RxJS

Unsubscribe

Page 55: Reactive Programming and RxJS

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.