Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Programação Reativa com RxJS
Search
Jonata Weber
May 27, 2017
Technology
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Programação Reativa com RxJS
Jonata Weber
May 27, 2017
Transcript
44 slides
Programação Reativa com RxJS Por Jonata Weber
@JonataWeber
None
None
Programação Reativa
Reactive programming is programming with asynchronous data streams.
Async em Web apps • AJAX • User Events (mouse
clicks, mouvemoves, keyups, etc) • Animations • Sockets • Workers
Por que usar RP?
None
callback É a maneira mais primitiva de trabalhar com async
no JavaScript getSomeData((data) => { console.log('data received', data); });
Callback Hell
Promises Provê uma solução simples getData(id) .then(data => { doStuff(data);
return getSomeData(data.parentId); }) .then(data => { doStuff(data); return getSomeData(data.parentId); })
Promises • Garante o Futuro • Imutável • Único valor
• Caching
Promises let promise = new Promise((resolve, reject) => { let
success = doSomethingAsync(); if (success) { resolve("Stuff worked!"); } else { reject(Error("It broke")); } });
Promises let promise = new Promise((resolve, reject) => { let
success = doSomethingAsync(); if (success) { resolve("Stuff worked!"); } else { reject(Error("It broke")); } });
Promises let promise = new Promise((resolve, reject) => { let
success = doSomethingAsync(); if (success) { resolve("Stuff worked!"); } else { reject(Error("It broke")); } });
Promises Pendente Realizada Rejeitado Estabelecido
Promises Pendente Realizada Rejeitado Estabelecido Não pode ser cancelada!!!
GET /search?q=pagode Search com Promises
GET /search?q=pop GET /search?q=pagode Search com Promises
GET /search?q=pagode GET /search?q=pop Search com Promises
Processará algo inútil Search com Promises GET /search?q=pagode GET /search?q=pop
GET /search?q=pagode Cenário ideal
GET /search?q=pop GET /search?q=pagode Cenário ideal
GET /search?q=pop GET /search?q=pagode Cenário ideal Abortar a requisição anterior
RxJS
RxJS is a library for composing asynchronous and event-based programs
by using observable sequences.
ReactiveX is a combination of the best ideas from the
Observer pattern, the Iterator pattern, and functional programming
Java: RxJava JavaScript: RxJS C#: Rx.NET Python: RxPY Ruby: Rx.rb
PHP: RxPHP Go: RxGo Kotlin: RxKotlin C++: RxCpp Lua: RxLua Groovy: RxGroovy JRuby: RxJRuby Swift: RxSwift Elixir: reaxive Dart: RxDart C# (Unity): UniRx
Demo
Hello World Rx.Observable .of(1, 2, 3, 4, 5) .subscribe(n =>
console.log(n)); http://jsbin.com/muxigepeju/edit?js,console
const btn = document.querySelector('button'); Rx.Observable.fromEvent(btn, 'click') .throttleTime(250) .scan(count => count
+ 1, 0) .subscribe(count => console.log(`Clicked ${count} times`)); Contador de Cliques http://jsbin.com/qifumej/edit?js,console,output
None
Transformation Operators • buffer • bufferCount • bufferTime • bufferToggle
• bufferWhen • concatMap • concatMapTo • exhaustMap • expand • groupBy • map • mapTo • mergeMap • mergeMapTo • mergeScan • pairwise • partition • pluck • scan • switchMap • switchMapTo • window • windowCount • windowTime • windowToggle • windowWhen
Demo http://jsbin.com/fuviwin/edit?js,console,output
Observable
Single Multiple Pull Function Iterator Push Promise Observable
Exemplo let observable = Rx.Observable.create((observer) => { observer.next(1); observer.next(2); observer.next(3);
setTimeout(() => { observer.next(4); observer.complete(); }, 1000); });
let observable = Rx.Observable.create((observer) => { observer.next(1); observer.next(2); observer.next(3); setTimeout(()
=> { observer.next(4); observer.complete(); }, 1000); }); console.log('just before subscribe'); observable.subscribe({ next: x => console.log('got value ' + x), error: err => console.error('something wrong occurred: ' + err), complete: () => console.log('done'), }); console.log('just after subscribe');
Subjects
Demo http://jsbin.com/ribosa/edit?js,console
Onde posso aprender mais sobre RxJS?
Referências • http://reactivex.io/rxjs/manual/overview.html#subject • https://www.gitbook.com/book/btroncone/learn-rxjs/ details • https://xgrommx.github.io/rx-book/why_rx.html • https://github.com/ReactiveX/rxjs
• https://www.youtube.com/watch?v=COviCoUtwx4
Obrigado! @JonataWeber
More Decks by Jonata Weber
See All by Jonata Weber
PHPStan - Analisador Estático
jonataa
0
130
PHP Moderno
jonataa
0
120
TemDendê: Desenvolvimento PHP a Moda Baiana
jonataa
0
65
O que esperar de um profissional de TI
jonataa
0
59
A onda agora é função como serviço
jonataa
0
46
Programação Funcional com Acarajé e Dendê
jonataa
0
84
Curso de Programação Funcional com JavaScript
jonataa
0
190
Medindo a Performance de Códigos PHP
jonataa
0
81
5 motivos para você participar de eventos
jonataa
0
160
Other Decks in Technology
See All in Technology
OSSとミニPCと私
anatofuz
1
120
新規事業開発でのAWS活用成功談&失敗談! 〜新規事業開発を専門に行うRelicならではのAWS活用〜
amixedcolor
1
160
データ界隈LT祭の運営のふりかえり
yoshimura_datam
0
110
メルカリの小規模チーム「Pod」で、 エンジニアがデータアナリストなしで、 AIを使ってデータ分析の自走を目指す取り組み
jackojacko_
1
370
[DBRE Summit 26] DBRE はデータベース運用をどう変えたのか
_awache
0
140
ブース設計、 お前もプロダクトだったのか / So Booth Design Was a Product All Along
akihiro0038
0
190
専門家に使ってもらうAIプロダクトをつくる - 病院の医事課向けDPCコーディング支援システムの設計と評価
hagino3000
4
1.1k
Kubernetes, Agones, WebRTC, GPU で作る クラウドゲーミング基盤を本番運用に乗せるまで
vivion
1
290
Kiro のリモートワークスペース: IDE は手元のままで、ワークスペースをクラウド、コンテナ、自前のマシンに置く
inariku
PRO
2
260
フルTypeScript × AI駆動開発で開発量が数倍に (JSConf JP 2026 スポンサーLT:NCDC株式会社)
keitaibaraki
0
580
OWASP AI Agentic Top10に準拠するクラウドネイティブなガードレールの実践(CNDW 2026)
keitah
1
460
フロントエンドのテストカバレッジは 100%強制がいい
bengo4com
7
3.9k
Featured
See All Featured
The Curse of the Amulet
leimatthew05
4
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
Test your architecture with Archunit
thirion
2
2.5k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
370
Writing Fast Ruby
sferik
630
63k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
GitHub's CSS Performance
jonrohan
1033
470k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
630
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
540