SlideShare a Scribd company logo
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!

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 

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