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
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
63
O que esperar de um profissional de TI
jonataa
0
56
A onda agora é função como serviço
jonataa
0
42
Programação Funcional com Acarajé e Dendê
jonataa
0
82
Curso de Programação Funcional com JavaScript
jonataa
0
190
Medindo a Performance de Códigos PHP
jonataa
0
79
5 motivos para você participar de eventos
jonataa
0
160
Other Decks in Technology
See All in Technology
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
540
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
1
780
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
140
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
7
2.8k
USB PDを使ってスマホを労わりたい
raspython3
0
150
「Docker Desktop不要の時代」は 来たのか?
ueponx
0
470
今さら理解するウェブフォントver.2026
takanorip
3
650
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
300
Codex概要
ymiya55
0
500
Jetson Orin Nanoとk3sとローカルLLMで音声文字起こしシステム作ってみた
y_sera15
0
120
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
180
Featured
See All Featured
Fireside Chat
paigeccino
43
4.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Writing Fast Ruby
sferik
630
63k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
480
Abbi's Birthday
coloredviolet
4
10k
The Pragmatic Product Professional
lauravandoore
37
7.5k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
Designing Experiences People Love
moore
143
24k
Utilizing Notion as your number one productivity tool
mfonobong
4
610
Un-Boring Meetings
codingconduct
0
450
Transcript
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