SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
wendelnascimento wnascimentow
Wendel Nascimento
Front end engineer @SENAI
Programação reativa
O que é programação
reativa?
reativo
adj. (1858)
1 que faz reagir, que
provoca reação;
reagente
2 eletr eletrôn fís
relativo a reatância
Programação blocante
if(x < 10) {
foo(x);
bar(x);
baz(x);
console.log("Done");
}
Este é um processo
imperativo/estruturado
CONTROLE
FLUXO NEM SEMPRE
BEM ESTABELECIDO
PRÓS…
FILAS - CONCORRÊNCIA
CÓDIGOS DE DIFÍCIL
LEITURA
NÃO ESCALÁVEL
CONTRAS…
Programação não blocante
Callbacks
if(x < 10) {
foo(x);
setTimeout(() =>
bar(x),
1000
);
baz(x);
console.log("Done");
}
SIMPLICIDADE
NÃO BLOCANTE
PRÓS…
FRÁGIL
CALLBACK HELL
CONTRAS…
Callback hell
PS: Nem todo callback é
assíncrono
Promises
if(x < 10) {
logValues(x)
.then(() =>
console.log(“Done”));
}
if(x < 10) {
logValues(x)
.then(() =>
console.log(“Done”));
}
Sim, Promises usam callbacks
PRÓS… MAIS SIMPLICIDADE
NÃO BLOCANTE
CÓDIGO LIMPO
NÃO CANCELÁVEL
É UM STREAM COM
INÍCIO E FIM
CONTRAS…
Observables
if(x < 10) {
logValues(x)
.subscribe(() =>
console.log(“Done”));
}
if(x < 10) {
logValues(x)
.subscribe(() =>
console.log(“Done”));
}
Sim, Observables também
usam callbacks
PRÓS… MAIS SIMPLICIDADE
NÃO BLOCANTE
CÓDIGO LIMPO
CANCELÁVEL
É UM STREAM QUE
PODE NUNCA TER FIM
NÃO ENCADEÁVELCONTRAS…
Calma. Observable +
Subscribe é tipo…
Promise???
Sim e não
“Observable is Promise++”
Andre Staltz
É simples. Observable é nada
mais que um stream
assíncrono infinito
var el = document.getElementById("t");
el.addEventListener(
"click",
handleClick
);
Então eu sempre programei
de forma reativa?
Sempre utilizamos funções
reativas porém muitas
vezes não sabemos disso
Mas agora vamos usar
O problema da Netflix era
não poder cancelar
requisições
Eles resolveram com RxJS e
RxJava
ECONOMIZAR TEMPO
ESCALAR SUA
APLICAÇÃO
E MUITO MAIS
TER UM CÓDIGO LIMPO
E FÁCIL MANUTENÇÃO
COM RXJS
VOCÊ IRÁ…
Hora da ação
Você conhece a terceira lei
de Newton?
Então vamos falar de reação
Com JS TS
Operadores e Objetos core
do RxJS
OBSERVABLES
Já usou qualquer coisa
assíncrona WhatsApp,
Messenger ou qualquer
outro mensageiro?
Já fez alguma pesquisa no
Google Maps?
SWITCHMAP
Já fez alguma pesquisa no
Google Maps?
DEBOUNCETIME
Já fez alguma pesquisa no
Google Maps?
DISTINCTUNTILCHANGED
Livestream?
SUBSCRIBE
Isso é ser reativo
wendelnascimento wnascimentow
Wendel Nascimento
Front end engineer @SENAI
Programação reativa com RxJS e Angular

Weitere ähnliche Inhalte

Andere mochten auch

Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.Angular
Evan Schultz
 
ReactiveX-SEA
ReactiveX-SEAReactiveX-SEA
ReactiveX-SEA
Yang Yang
 

Andere mochten auch (20)

Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Functional Reactive Angular 2
Functional Reactive Angular 2 Functional Reactive Angular 2
Functional Reactive Angular 2
 
Turbolinks 5 + PWA (Progressive Web Apps)
Turbolinks 5 + PWA (Progressive Web Apps)Turbolinks 5 + PWA (Progressive Web Apps)
Turbolinks 5 + PWA (Progressive Web Apps)
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Angular redux
Angular reduxAngular redux
Angular redux
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.Angular
 
FRP with Ractive and RxJS
FRP with Ractive and RxJSFRP with Ractive and RxJS
FRP with Ractive and RxJS
 
ReactiveX-SEA
ReactiveX-SEAReactiveX-SEA
ReactiveX-SEA
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScript
 
Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Reactive Extensions for JavaScript
Reactive Extensions for JavaScriptReactive Extensions for JavaScript
Reactive Extensions for JavaScript
 
Reactive Programming and RxJS
Reactive Programming and RxJSReactive Programming and RxJS
Reactive Programming and RxJS
 
RxJS - The Reactive Extensions for JavaScript
RxJS - The Reactive Extensions for JavaScriptRxJS - The Reactive Extensions for JavaScript
RxJS - The Reactive Extensions for JavaScript
 
RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 

Programação reativa com RxJS e Angular