SlideShare una empresa de Scribd logo
1 de 53
Descargar para leer sin conexión
1 y 2 de Marzo
#t3chfest2018
Entendamos de una vez qué
es eso de la reactividad…
Sema García
@semagarcia
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
“Cordobéh”
JavaScript Architect
Trainer & speaker
Who am I?
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
§Rx introduction
§Atypical examples
§This seems to be an observable
§Observables and its friends
§More examples
Agenda
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
A brief survey
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Reactive
eXtensions
Far time ago…
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
JSSkills
Time
Rx
Event loop
Promises
Clousures
Learning curve cliff?
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Rx = FP + Observer + Iterator
Mixture of concepts:
• Functional programming
• Observer pattern
• Iterator pattern
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
The reactive programming is
a paradigm with
asynchronous data streams.
to operate
What’s reactive programming
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
paradigm
What’s reactive programming
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Reactive eXtensions
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Typical first example: values over the time
Please, pay attention to that complex and huge equation:
c = a + b;
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Typical first example: values over the time
All variables in our system change
over the time, and therefore, they
are “observables”
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
a = 1; b = 3;
c = a + b; // 4
a = 3;
c = ? // 4!!!
Typical first example: values over the time
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
c = 4??
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
A good example of “reactive model"
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Excel: reactive datasheet
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Reactive step-by-step sum
Step by step sum with async (future) values
1 3 add 4
a b c
7 8
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Over the time
JS-ASYNCHRONY
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Example 01
Example 01
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Standardizing methods
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Kind of callbacks identified
I’d need…
• A callback for each event / data
• A callback for error handling
• A callback for completion
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Example 02
Example 02
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
An event is coming!
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
An event is coming!
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Money, money…
VALUE
DATA STREAM
ASYNC TONS OF OBSERVERS
OBSERVABLE
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Rx in the nature
OBSERVABLE
OBSERVERS
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
¡¡GRRRR
RRR!!!
Ohh! He says
“GRRRRRRR”!!
Rx in the nature
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Example 02
Lion example
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Streams everywhere…
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Observables…
Observables are functions, so,
functions don’t do anything until
they are called
Observables
are
lazy
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
How to create an Observable?
Many forms:
• .create(function);
• .of(value);
• .from(AnArray);
• .fromEvent(element, event);
• .fromPromise(p);
• .range(min, max);
• .interval(period);
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Subscription
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Subscription
A “subscription” represents the
execution of an Observable, useful
for cancelling it
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Subscription
A subscription to an observable ends if one of
the following occurs:
1. The consumer explicitely unsubscribes
2. The observable invokes the complete()
method on the observer
3. The observable invokes the error() method
on the observer
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Subscription
Its most important method:
.unsuscribe()
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Pay attention to this advice…
TO UNSUSCRIBE!!
DON’T FORGET
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
A new friend in Rx world: Subject
WTF is a Subject?
A subject represents an object that is
both an observable as well as an
observer. Each notification is
broadcasted to all subscribed
observers.
“Data producer – data consumer…”
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
A new friend in Rx world: Subject
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
A new friend in Rx world: Subject
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Type of Subjects
There are four types:
• PublishSubject: emits all the subsequent items of the
source Observable at the time of subscription.
• ReplaySubject: emits all the items of the source
Observable, regardless of when the subscriber subscribes.
• BehaviourSubject: emits the most recently emitted item
and all the subsequent items of the source Observable
when an observer subscribes to it.
• AsyncSubject: only emits the last value of the source
Observable(and only the last value) only after that source
Observable completes.
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Operators…
• Creationals
• Filters
• Maths
• Transforms
• Combinations
• Error handling
… for all use cases:
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Operators…
An “operator” is just a function
that takes an observable and
returns a new observable
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Marble (formal) diagram
Events/Data
Streams’ end
Error occurred
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
RxMarbles
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
RxJS & Angular
Angular Auth Example
Comp. 1 Comp. 2 Comp. 3
Header (+ AuthService)
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
RxJS & Angular
- Http requests
- Forms
- Async inputs
- Components inter-communication
- Router / Navigating
- Change Detection
- Animations
- And much more…
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
RxJS & Redux (in Angular)
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
This is just the beginning
Further topics in RxJS:
- Error (catch, retry) and parallel
observables
- Operators (even more) in depth
- Schedulers
- More subject use cases
- .pipe() and lettable operators
- RxJS 6/7…
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Conclusions
Conclusions…
RxJS is so cute!
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Examples in the repo!
https://github.com/semagarcia/
rxjs-t3chfest-reactividad
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Make your questions!
#T3chFest2018@semagarcia – Entiende eso de la reactividad de una vez por todas
Make your questions!

Más contenido relacionado

Último

EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial Uninove
FagnerLisboa3
 
Modulo-Mini Cargador.................pdf
Modulo-Mini Cargador.................pdfModulo-Mini Cargador.................pdf
Modulo-Mini Cargador.................pdf
AnnimoUno1
 

Último (11)

PROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
PROYECTO FINAL. Tutorial para publicar en SlideShare.pptxPROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
PROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
 
Avances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estosAvances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estos
 
EL CICLO PRÁCTICO DE UN MOTOR DE CUATRO TIEMPOS.pptx
EL CICLO PRÁCTICO DE UN MOTOR DE CUATRO TIEMPOS.pptxEL CICLO PRÁCTICO DE UN MOTOR DE CUATRO TIEMPOS.pptx
EL CICLO PRÁCTICO DE UN MOTOR DE CUATRO TIEMPOS.pptx
 
Avances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvanaAvances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvana
 
pruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITpruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNIT
 
Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21
 
Refrigerador_Inverter_Samsung_Curso_y_Manual_de_Servicio_Español.pdf
Refrigerador_Inverter_Samsung_Curso_y_Manual_de_Servicio_Español.pdfRefrigerador_Inverter_Samsung_Curso_y_Manual_de_Servicio_Español.pdf
Refrigerador_Inverter_Samsung_Curso_y_Manual_de_Servicio_Español.pdf
 
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
 
EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial Uninove
 
Modulo-Mini Cargador.................pdf
Modulo-Mini Cargador.................pdfModulo-Mini Cargador.................pdf
Modulo-Mini Cargador.................pdf
 
How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.
 

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

T3chFest 2018 - Entendamos de una vez qué es eso de la reactividad