Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rxjs
Search
Danila Marchenkov
September 13, 2017
Education
0
100
Rxjs
Danila Marchenkov
September 13, 2017
Tweet
Share
More Decks by Danila Marchenkov
See All by Danila Marchenkov
angular6
sprit3dan
0
73
angular5
sprit3dan
0
52
angular#4
sprit3dan
0
160
angular#3
sprit3dan
0
44
angular#2
sprit3dan
0
34
Angular#1
sprit3dan
0
52
HTML 5 Canvas
sprit3dan
0
44
Angular #6
sprit3dan
0
68
Angular #5
sprit3dan
0
120
Other Decks in Education
See All in Education
生態系ウォーズ - ルールブック
yui_itoshima
1
340
The knowledge panel is your new homepage
bradwetherall
0
210
Avoin jakaminen ja Creative Commons -lisenssit
matleenalaakso
0
2k
【ZEPホスト用メタバース校舎操作ガイド】
ainischool
0
120
探査機自作ゼミ2025スライド
sksat
3
840
Présentation_2nde_2025.pdf
bernhardsvt
0
320
Microsoft Office 365
matleenalaakso
0
2k
Réaliser un diagnostic externe
martine
0
320
Test-NUTMEG紹介スライド
mugiiicha
0
310
ROSConJP 2025 発表スライド
f0reacharr
0
260
2024-2025 CBT top items
cbtlibrary
0
140
アジャイルの知見から新卒研修作り、そして組織作り
pokotyamu
0
110
Featured
See All Featured
A Tale of Four Properties
chriscoyier
162
23k
Building Adaptive Systems
keathley
44
2.8k
BBQ
matthewcrist
89
9.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Code Reviewing Like a Champion
maltzj
527
40k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
1.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
192
56k
How to Ace a Technical Interview
jacobian
280
24k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Transcript
ReactiveX Marchenkov Danila, Software Developer
None
RxJS RxJava Rx.NET RxScala RxSwift RxClosure RxCpp RxGo RxGroovy RxJRuby
RxPHP RxPY Rx.rb RxDart RxLua
FRP Asynchronous - Observables Synchronous - Iterators
Observable
DOM-events Async operations Any data flow within app
Api?
• audit • auditTime • filter • last • buffer
• bufferWhen • catch • combine • combineAll • combineLatest • concat • count • debounce • delay • distinct • do • every • exhaust • expand • findIndex • find • forEach • groupBy • isEmpty • lift • map • mapTo • max • merge • mergeAll • min • multicast
const obs = Observable.from([1, 2, 3, 4]); obs.subscribe(it => console.log(‘obs’
+ it)); >obs1 >obs2 >obs3 >obs4
const obs = Observable.from([1, 2, 3, 4]); obs .map(val =>
`obs${val}`) .subscribe(it => console.log(it)); >obs1 >obs2 >obs3 >obs4
let emitter; const obs: Observable<number> = new Observable(e => emitter
= e); [1, 2, 3, 4].forEach(it => emitter.next(it)); obs.subscribe(it => console.log(it));
let emitter; const obs: Observable<number> = new Observable(e => emitter
= e); [1, 2, 3, 4].forEach(it => emitter.next(it)); obs.subscribe(it => console.log(it)); >ERROR TypeError: Cannot read property 'next' of undefined
let emitter; const obs: Observable<number> = new Observable(e => emitter
= e); obs.subscribe(it => console.log(it)); [1, 2, 3, 4].forEach(it => emitter.next(it)); >1 >2 >3 >4
import { Observable } from ‘rxjs/Rx'; export class Service {
private stream: Observable<T> = new Observable(obs => this.emitter = obs) private emitter; public get onSteamEvent() { return this.steam; } private someMethod() { . . . this.emitter.next({someData}); } }
import { Observable } from ‘rxjs/Rx'; export class Service {
private stream: Observable<T> = new Observable(obs => this.emitter = obs).share(); private emitter; public get onSteamEvent() { return this.steam; } private someMethod() { . . . this.emitter.next({someData}); } }
HOT vs COLD Observables
var cold = new Observable((observer) => { var producer =
new Producer(); // have observer listen to producer here }); COLD
HOT var producer = new Producer(); var hot = new
Observable((observer) => { // have observer listen to producer here });
Multicasting
const obs: Observable<number> = new Observable(e => emitter = e);
obs.subscribe(it => console.log(it)); obs.map(it => it + 1).subscribe(it => console.log(it)); [1, 2, 3, 4].forEach(it => emitter.next(it));
const obs: Observable<number> = new Observable(e => emitter = e);
obs.subscribe(it => console.log(it)); obs.map(it => it + 1).subscribe(it => console.log(it)); [1, 2, 3, 4].forEach(it => emitter.next(it)); >2 >3 >4 >5
const obs = new Observable<number>(e => emitter = e).share(); obs.subscribe(it
=> console.log(it)); obs.map(it => it + 1).subscribe(it => console.log(it)); [1, 2, 3, 4].forEach(it => emitter.next(it)); >1 >2 >2 >3 >3 >4 >5
Profit over Promise?
Observable > Promise • Observable is reusable • Observable is
cancellable • A lot of powerful operators • Hot & Cold observables • Merging a lot of observables • Multiple pipeline instead of only .then, .catch • Obs can become Promise :3
Subject
or BehaviourSubject AsyncSubject AnonymousSubject ReplaySubject
Every Subject is an Observable. Every Subject is an Observer.
let subj = new Subject(); subj.next(1); subj.subscribe(it => console.log(it)); subj.next(2);
>2
let lastNOperations = Infinity; let subj = new ReplaySubject(lastNOpearions); subj.next(1);
subj.subscribe(it => console.log(it)); subj.next(2); >1 >2
let subj = new BehaviorSubject(1); subj.subscribe(it => console.log(it)); subj.next(2); >1
>2
Careful
Subject will NOT be disposed after all subscribers disconnected Use
Subjects only in place, where two-way data flow is certainly needed!
Useful operations except map, reduce, filter, find
Distinct
Reduce
Repeat
Partition
Concat
Merge