SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
My gentle
introduction to RxJS
About me
Mattia Occhiuto
 
Front-end Software Engineer @ Tuotempo s.r.l.
Twitter  @MattiaOch
Github  mattiaocchiuto
Reactive Systems
 
“ Systems built as Reactive Systems are more flexible, loosely-
coupled and scalable. This makes them easier to develop and
amenable to change. They are significantly more tolerant of
failure and when failure does occur they meet it with elegance
rather than disaster. Reactive Systems are highly responsive,
giving users effective interactive feedback.
 
 
from www.reactivemanifesto.org
So...
Responsive - system respond in a timely manner where possible
Resilient - system stays responsive in case of failure
Elastic - scalable
Message driven - based on async messages
Reactive Systems are:
Reactive Programming
“ reactive programming is a programming
paradigm  oriented around data flows  and the
propagation of change. This means that it should be
possible to express static or dynamic data flows with
ease in the programming languages used, and that
the underlying execution model will automatically
propagate changes through the data flow.
 
 
from wikipedia
graphically ...
using asynchronous data streams
more declarative
more reusability
more testability
increase separation on concerns
A B
A B
Proactive Passive
Listenable Reactive
From Cycle.js documentation
Why we need it ?
Nowadays Modern Web Applications are complex
systems composed of asynchronous data coming from
many different sources:
 
user interaction (DOM-events)
AJAX call
device event (GPS)
web socket
web workers
reactive user interface (Model/View sync)
etc...
RxJS - The Observables way
Iterator                     +                   Observer
var arr = ['a', 'b', 'c'];
var iter = arr[Symbol.iterator]();
iter.next()
> { value: 'a', done: false }
iter.next()
> { value: 'b', done: false }
iter.next()
> { value: 'c', done: false }
iter.next()
> { value: undefined, done: true }
var el = document.getElementById("button");
el.addEventListener("click", doSomething);
RxJS - The Observables way
In short, an  Observable is an event stream which can
emit zero or more events, and may or may not finish. If it
finishes, then it does so by either emitting an error or a
special “complete” event
And What about operators?
Array [1, 2, 3, 4, 5]
  .map
  .filter
  .reduce
  .each
  ...
Stream {...1..2.....3...4......5..}
  .map
  .filter
  .reduce
  .each
  ...(and > 120 other operators)
 
Both are collection and both of course has
powerful operators!
And What about operators?
How they looks like
var source = Rx.Observable.fromEvent($input, 'keyup')
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (e) {
console.log('Error: ' + e);
},
function () {
console.log('Completed');
}
);
subscription.dispose();
data pushed
centralised error handling
notification on complete
disposable
Who is the right source?
Easily: everything
More precisely (?): every data structure or async data source
RxJS here we are!
Reactive programming
Events as collection of data
Manipulation over Array-like "operators"
Let's code!
https://github.com/mattiaocchiuto/talks/blob/master/RxJS/
Conslusion
Cons:
too many operators that can lead to the same
results and to remember!
learning curve
not enough examples and tutorial (at least for me)
Conslusion
Pros:
great abstraction for async and events data/operations
easy way to compose async data stream
support for many languages: [Java, .Net, Scala, C#, Clojure, C++,
Ruby, Python, Swift, etc..]
performance => for big array processing, it remove
intermediate array allocation
super powerful operators
Questions?
Thanks!

Mais conteúdo relacionado

Mais procurados

Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 

Mais procurados (20)

An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
 
Cascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the StreamsCascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the Streams
 
Reactive Extensions for JavaScript
Reactive Extensions for JavaScriptReactive Extensions for JavaScript
Reactive Extensions for JavaScript
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJava
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Reactive cocoa made Simple with Swift
Reactive cocoa made Simple with SwiftReactive cocoa made Simple with Swift
Reactive cocoa made Simple with Swift
 
RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
GKAC 2015 Apr. - RxAndroid
GKAC 2015 Apr. - RxAndroidGKAC 2015 Apr. - RxAndroid
GKAC 2015 Apr. - RxAndroid
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Learn You a ReactiveCocoa for Great Good
Learn You a ReactiveCocoa for Great GoodLearn You a ReactiveCocoa for Great Good
Learn You a ReactiveCocoa for Great Good
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
ReactiveCocoa Goodness - Part I of II
ReactiveCocoa Goodness - Part I of IIReactiveCocoa Goodness - Part I of II
ReactiveCocoa Goodness - Part I of II
 
Using akka streams to access s3 objects
Using akka streams to access s3 objectsUsing akka streams to access s3 objects
Using akka streams to access s3 objects
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Introduction to rx java for android
Introduction to rx java for androidIntroduction to rx java for android
Introduction to rx java for android
 

Semelhante a My Gentle Introduction to RxJS

Prezo tooracleteam (2)
Prezo tooracleteam (2)Prezo tooracleteam (2)
Prezo tooracleteam (2)
Sharma Podila
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
Alexander Mostovenko
 

Semelhante a My Gentle Introduction to RxJS (20)

DZone_RC_RxJS
DZone_RC_RxJSDZone_RC_RxJS
DZone_RC_RxJS
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
 
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
 
Intro to Rx Java
Intro to Rx JavaIntro to Rx Java
Intro to Rx Java
 
Reactive programming and RxJS
Reactive programming and RxJSReactive programming and RxJS
Reactive programming and RxJS
 
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
 
Prezo tooracleteam (2)
Prezo tooracleteam (2)Prezo tooracleteam (2)
Prezo tooracleteam (2)
 
Next generation of frontend architectures
Next generation of frontend architecturesNext generation of frontend architectures
Next generation of frontend architectures
 
From zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptFrom zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScript
 
Reactive programming with cycle.js
Reactive programming with cycle.jsReactive programming with cycle.js
Reactive programming with cycle.js
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
 
Event driven application
Event driven applicationEvent driven application
Event driven application
 
JS Experience 2017 - Reactive Interfaces com React & RxJS
JS Experience 2017 - Reactive Interfaces com React & RxJSJS Experience 2017 - Reactive Interfaces com React & RxJS
JS Experience 2017 - Reactive Interfaces com React & RxJS
 
ml mini project (1).pptx
ml mini project (1).pptxml mini project (1).pptx
ml mini project (1).pptx
 
Demystifying Reactive Programming
Demystifying Reactive ProgrammingDemystifying Reactive Programming
Demystifying Reactive Programming
 
From zero to hero with the reactive extensions for java script
From zero to hero with the reactive extensions for java scriptFrom zero to hero with the reactive extensions for java script
From zero to hero with the reactive extensions for java script
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVM
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

My Gentle Introduction to RxJS

  • 2. About me Mattia Occhiuto   Front-end Software Engineer @ Tuotempo s.r.l. Twitter  @MattiaOch Github  mattiaocchiuto
  • 3. Reactive Systems   “ Systems built as Reactive Systems are more flexible, loosely- coupled and scalable. This makes them easier to develop and amenable to change. They are significantly more tolerant of failure and when failure does occur they meet it with elegance rather than disaster. Reactive Systems are highly responsive, giving users effective interactive feedback.     from www.reactivemanifesto.org
  • 4. So... Responsive - system respond in a timely manner where possible Resilient - system stays responsive in case of failure Elastic - scalable Message driven - based on async messages Reactive Systems are:
  • 5. Reactive Programming “ reactive programming is a programming paradigm  oriented around data flows  and the propagation of change. This means that it should be possible to express static or dynamic data flows with ease in the programming languages used, and that the underlying execution model will automatically propagate changes through the data flow.     from wikipedia
  • 6. graphically ... using asynchronous data streams more declarative more reusability more testability increase separation on concerns A B A B Proactive Passive Listenable Reactive From Cycle.js documentation
  • 7. Why we need it ? Nowadays Modern Web Applications are complex systems composed of asynchronous data coming from many different sources:   user interaction (DOM-events) AJAX call device event (GPS) web socket web workers reactive user interface (Model/View sync) etc...
  • 8. RxJS - The Observables way Iterator                     +                   Observer var arr = ['a', 'b', 'c']; var iter = arr[Symbol.iterator](); iter.next() > { value: 'a', done: false } iter.next() > { value: 'b', done: false } iter.next() > { value: 'c', done: false } iter.next() > { value: undefined, done: true } var el = document.getElementById("button"); el.addEventListener("click", doSomething);
  • 9. RxJS - The Observables way In short, an  Observable is an event stream which can emit zero or more events, and may or may not finish. If it finishes, then it does so by either emitting an error or a special “complete” event
  • 10. And What about operators? Array [1, 2, 3, 4, 5]   .map   .filter   .reduce   .each   ... Stream {...1..2.....3...4......5..}   .map   .filter   .reduce   .each   ...(and > 120 other operators)   Both are collection and both of course has powerful operators!
  • 11. And What about operators?
  • 12. How they looks like var source = Rx.Observable.fromEvent($input, 'keyup') var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (e) { console.log('Error: ' + e); }, function () { console.log('Completed'); } ); subscription.dispose(); data pushed centralised error handling notification on complete disposable
  • 13. Who is the right source? Easily: everything More precisely (?): every data structure or async data source
  • 14. RxJS here we are! Reactive programming Events as collection of data Manipulation over Array-like "operators"
  • 16. Conslusion Cons: too many operators that can lead to the same results and to remember! learning curve not enough examples and tutorial (at least for me)
  • 17. Conslusion Pros: great abstraction for async and events data/operations easy way to compose async data stream support for many languages: [Java, .Net, Scala, C#, Clojure, C++, Ruby, Python, Swift, etc..] performance => for big array processing, it remove intermediate array allocation super powerful operators