SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Jalpesh Vadgama
@jalpesh, Co-Founder, FutureStack Solution
Top 10 RxJs
Operators in Angular
About Me
• More than 14 years of experience in Web Development,
Cloud Solutions and Enterprise Grade Applications.
• Co-Founder of Future Stack Solution
http://www.futurestacksolution.com
• Awarded Microsoft MVP 8 times. Currently MVP in Visual
Studio and Development Technologies.
• A community guy love to network with new people!.
• An enthusiast developer trying to learn everyday
something new
Agenda
• What problems RxJs going to solve?
• Callback, Promises and What is the problem with that?
• Observables
• Demo with Observables and Of operator
• Different operators available in RxJs
• Questions and Answer
“To think creatively, we must be
able to look afresh at what we
normally take for granted”
- George Keller
Bringing functional
programming to
JavaScript
Callbacks
functionToCallXHR() {
function Success(successParams) {
// Handle success
}
function Failure(failureParams) {
// Handle failure
}
}
Promises
let result = http.get("your api url");
result.then(function(params){
},
function (params){
// Handle failure
}
);
// Handle success
What is I want to retry again
after failure?
Observables
What is Observables?
An observable is essentially a stream (a stream of events, or
data) and compared to a Promise, an Observable can be
cancelled..
What is Observables?
An observable have at least participant
The Creator
The Subscriber:
result.subscribe(){
next => {handleYourEmittedValue(next)},
console.error,
()=> console.log("All finished");
}
let result = http.get("your api url");
Operators
• Operators are functions that operate on observables and returns the
new observables
• They are pure functions that transform information in the observable
stream that create new observables, often based on the current
observable
• Most importantly, the operators in RxJS allow for complex
asynchronous code that can be easily composed in a declarative
manner.
.
Operator Demo
Of operator
• Of operators convert any object into observables
• Mostly we are using it from to convert a JSON retrieve from our apis
Concat operator
• Concat operator emit the emissions from two or more Observables
without interleaving them
• You can think of concat like a line at a ATM, the next transaction
(subscription) cannot start until the previous completes!
// Simulate HTTP requests
const getPostOne$ = Rx.Observable.timer(3000).mapTo({ id: 1 });
const getPostTwo$ = Rx.Observable.timer(1000).mapTo({ id: 2 });
Rx.Observable.concat(getPostOne$, getPostTwo$)
.subscribe(res => console.log(res));
MergeMap operator
• The merge map operator is handy when the requirement is to
merge response from two observables
const firstNameObs$ = of('Jalpesh');
const lastNameObs$ = of('Vadgama');
const finalObs$ = firstNameObs$.pipe(
mergeMap(event1 => lastNameObs$.pipe(
map(event2 => event1 + ' ' + event2)))
);
const subscription = finalObs$.subscribe((value) => console.log(value));
// outputs: Jalpesh Vadgama
Filter operator
• The filter operator is handy when you need to filter something
• The following example will get an observable that emit the numbers.
We will use the filter operator to only emit the even numbers
this.numberService.getNumbers().pipe(
filter(n => n % 2 === 0),
)
.subscribe(result => console.log(result));
Delay operator
• The Delay operator emits values after some delay
const sub: Subject<number> = new Subject<number>();
sub.pipe(
delay(500)
).subscribe((val: number) => {
console.log(val);
});
sub.next(0);
sub.next(1);
sub.next(2);
// after 500ms delay will emit all the val
Retry operator
• if a source Observable emits an error, resubscribe to it in the hopes
that it will complete without error
getBook(id: number): Observable < Book > {
let url = this.bookUrl + "/" + id;
return this.http.get<Book>(url).pipe(
retry(3),
// retry the failed request up to 3 times
catchError(err => {
console.log(err);
return of(null);
})
);
}
Zip operator
• Multiple observables emitting at alternate intervals
const sourceOne = of('Hello');
const sourceTwo = of('World!');
const sourceThree = of('Goodbye');
const sourceFour = of('World!');
//wait until all observables have emitted a value
then emit all as an array
const example = zip(
sourceOne,
sourceTwo.pipe(delay(1000)),
sourceThree.pipe(delay(2000)),
sourceFour.pipe(delay(3000))
);
//output: ["Hello", "World!", "Goodbye", "World!"]
Distinct operator
• Returns an Observable that emits all items emitted by the source
Observable that are distinct by comparison from previous items.
of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1).pipe(
distinct(),
)
.subscribe(x => console.log(x));
// Output: 1, 2, 3, 4
IsEmpty operator
• Emits false if the input observable emits any values, or emits true if the input
observable completes without emitting any values.
const source = new Subject<string>();
const result = source.pipe(isEmpty());
source.subscribe(x => console.log(x));
result.subscribe(x => console.log(x));
source.next('a');
source.next('b');
source.next('c');
source.complete();
// Results in:
// a
// false
// b
// c
10th Operator
• There are more than 50 operators are there.
• You can look at those operators at - https://rxjs-
dev.firebaseapp.com/api/operators/
• Even you can build your own operators!!
Q&A
Thank you!
• Email: jalpesh@futurestacksolution.com
• Blog: https://www.dotnetjalps.com
• YouTube: http://bit.ly/codewithjv
• GitHub: https://github.com/jalpeshvadgama
• Twitter: @Jalpesh

Weitere ähnliche Inhalte

Was ist angesagt?

RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolvedtrxcllnt
 
Introduction for Master Class "Amazing Reactive Forms"
Introduction for Master Class "Amazing Reactive Forms"Introduction for Master Class "Amazing Reactive Forms"
Introduction for Master Class "Amazing Reactive Forms"Fabio Biondi
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquareApigee | Google Cloud
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 
RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019Fabio Biondi
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentationritika1
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practicesIwan van der Kleijn
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 

Was ist angesagt? (20)

RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Introduction for Master Class "Amazing Reactive Forms"
Introduction for Master Class "Amazing Reactive Forms"Introduction for Master Class "Amazing Reactive Forms"
Introduction for Master Class "Amazing Reactive Forms"
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Angular
AngularAngular
Angular
 
Angular 2 observables
Angular 2 observablesAngular 2 observables
Angular 2 observables
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 

Ähnlich wie Top 10 RxJs Operators in Angular

RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015Ben Lesh
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverMongoDB
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomyDongmin Yu
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016Frank Lyaruu
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Getting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamGetting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamSteve Lee
 
RxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMixRxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMixTracy Lee
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)jeffz
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowViliam Elischer
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Webnickmbailey
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleGeoff Ballinger
 
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Elixir Club
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기NAVER D2
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Morris Singer
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
State management in a GraphQL era
State management in a GraphQL eraState management in a GraphQL era
State management in a GraphQL erakristijanmkd
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 

Ähnlich wie Top 10 RxJs Operators in Angular (20)

RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node Driver
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Getting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamGetting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstream
 
RxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMixRxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMix
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Web
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's Finagle
 
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
State management in a GraphQL era
State management in a GraphQL eraState management in a GraphQL era
State management in a GraphQL era
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 

Mehr von Jalpesh Vadgama

Angular Ivy- An Overview
Angular Ivy- An OverviewAngular Ivy- An Overview
Angular Ivy- An OverviewJalpesh Vadgama
 
Building Real time Application with Azure SignalR Service
Building Real time Application with Azure SignalR ServiceBuilding Real time Application with Azure SignalR Service
Building Real time Application with Azure SignalR ServiceJalpesh Vadgama
 
Introduction to Active Directory
Introduction to Active DirectoryIntroduction to Active Directory
Introduction to Active DirectoryJalpesh Vadgama
 
Visual Studio 2017 and ASP.NET Core 1.1
Visual Studio 2017 and ASP.NET Core 1.1Visual Studio 2017 and ASP.NET Core 1.1
Visual Studio 2017 and ASP.NET Core 1.1Jalpesh Vadgama
 
Introduction to BOT Framework- Global Azure Bootcamp 2017
Introduction to BOT Framework- Global Azure Bootcamp 2017Introduction to BOT Framework- Global Azure Bootcamp 2017
Introduction to BOT Framework- Global Azure Bootcamp 2017Jalpesh Vadgama
 
Introduction to document db- Global Azure Bootcamp 2016
Introduction to document db- Global Azure Bootcamp 2016Introduction to document db- Global Azure Bootcamp 2016
Introduction to document db- Global Azure Bootcamp 2016Jalpesh Vadgama
 
Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...
Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...
Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...Jalpesh Vadgama
 

Mehr von Jalpesh Vadgama (7)

Angular Ivy- An Overview
Angular Ivy- An OverviewAngular Ivy- An Overview
Angular Ivy- An Overview
 
Building Real time Application with Azure SignalR Service
Building Real time Application with Azure SignalR ServiceBuilding Real time Application with Azure SignalR Service
Building Real time Application with Azure SignalR Service
 
Introduction to Active Directory
Introduction to Active DirectoryIntroduction to Active Directory
Introduction to Active Directory
 
Visual Studio 2017 and ASP.NET Core 1.1
Visual Studio 2017 and ASP.NET Core 1.1Visual Studio 2017 and ASP.NET Core 1.1
Visual Studio 2017 and ASP.NET Core 1.1
 
Introduction to BOT Framework- Global Azure Bootcamp 2017
Introduction to BOT Framework- Global Azure Bootcamp 2017Introduction to BOT Framework- Global Azure Bootcamp 2017
Introduction to BOT Framework- Global Azure Bootcamp 2017
 
Introduction to document db- Global Azure Bootcamp 2016
Introduction to document db- Global Azure Bootcamp 2016Introduction to document db- Global Azure Bootcamp 2016
Introduction to document db- Global Azure Bootcamp 2016
 
Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...
Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...
Ahmedabad- Global Azure bootcamp- Azure Storage Services- Global Azure Bootca...
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Top 10 RxJs Operators in Angular

  • 1. Jalpesh Vadgama @jalpesh, Co-Founder, FutureStack Solution Top 10 RxJs Operators in Angular
  • 2. About Me • More than 14 years of experience in Web Development, Cloud Solutions and Enterprise Grade Applications. • Co-Founder of Future Stack Solution http://www.futurestacksolution.com • Awarded Microsoft MVP 8 times. Currently MVP in Visual Studio and Development Technologies. • A community guy love to network with new people!. • An enthusiast developer trying to learn everyday something new
  • 3. Agenda • What problems RxJs going to solve? • Callback, Promises and What is the problem with that? • Observables • Demo with Observables and Of operator • Different operators available in RxJs • Questions and Answer
  • 4. “To think creatively, we must be able to look afresh at what we normally take for granted” - George Keller Bringing functional programming to JavaScript
  • 6. functionToCallXHR() { function Success(successParams) { // Handle success } function Failure(failureParams) { // Handle failure } }
  • 8. let result = http.get("your api url"); result.then(function(params){ }, function (params){ // Handle failure } ); // Handle success
  • 9. What is I want to retry again after failure?
  • 11. What is Observables? An observable is essentially a stream (a stream of events, or data) and compared to a Promise, an Observable can be cancelled..
  • 12. What is Observables? An observable have at least participant The Creator The Subscriber: result.subscribe(){ next => {handleYourEmittedValue(next)}, console.error, ()=> console.log("All finished"); } let result = http.get("your api url");
  • 13. Operators • Operators are functions that operate on observables and returns the new observables • They are pure functions that transform information in the observable stream that create new observables, often based on the current observable • Most importantly, the operators in RxJS allow for complex asynchronous code that can be easily composed in a declarative manner. .
  • 15. Of operator • Of operators convert any object into observables • Mostly we are using it from to convert a JSON retrieve from our apis
  • 16. Concat operator • Concat operator emit the emissions from two or more Observables without interleaving them • You can think of concat like a line at a ATM, the next transaction (subscription) cannot start until the previous completes! // Simulate HTTP requests const getPostOne$ = Rx.Observable.timer(3000).mapTo({ id: 1 }); const getPostTwo$ = Rx.Observable.timer(1000).mapTo({ id: 2 }); Rx.Observable.concat(getPostOne$, getPostTwo$) .subscribe(res => console.log(res));
  • 17. MergeMap operator • The merge map operator is handy when the requirement is to merge response from two observables const firstNameObs$ = of('Jalpesh'); const lastNameObs$ = of('Vadgama'); const finalObs$ = firstNameObs$.pipe( mergeMap(event1 => lastNameObs$.pipe( map(event2 => event1 + ' ' + event2))) ); const subscription = finalObs$.subscribe((value) => console.log(value)); // outputs: Jalpesh Vadgama
  • 18. Filter operator • The filter operator is handy when you need to filter something • The following example will get an observable that emit the numbers. We will use the filter operator to only emit the even numbers this.numberService.getNumbers().pipe( filter(n => n % 2 === 0), ) .subscribe(result => console.log(result));
  • 19. Delay operator • The Delay operator emits values after some delay const sub: Subject<number> = new Subject<number>(); sub.pipe( delay(500) ).subscribe((val: number) => { console.log(val); }); sub.next(0); sub.next(1); sub.next(2); // after 500ms delay will emit all the val
  • 20. Retry operator • if a source Observable emits an error, resubscribe to it in the hopes that it will complete without error getBook(id: number): Observable < Book > { let url = this.bookUrl + "/" + id; return this.http.get<Book>(url).pipe( retry(3), // retry the failed request up to 3 times catchError(err => { console.log(err); return of(null); }) ); }
  • 21. Zip operator • Multiple observables emitting at alternate intervals const sourceOne = of('Hello'); const sourceTwo = of('World!'); const sourceThree = of('Goodbye'); const sourceFour = of('World!'); //wait until all observables have emitted a value then emit all as an array const example = zip( sourceOne, sourceTwo.pipe(delay(1000)), sourceThree.pipe(delay(2000)), sourceFour.pipe(delay(3000)) ); //output: ["Hello", "World!", "Goodbye", "World!"]
  • 22. Distinct operator • Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items. of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1).pipe( distinct(), ) .subscribe(x => console.log(x)); // Output: 1, 2, 3, 4
  • 23. IsEmpty operator • Emits false if the input observable emits any values, or emits true if the input observable completes without emitting any values. const source = new Subject<string>(); const result = source.pipe(isEmpty()); source.subscribe(x => console.log(x)); result.subscribe(x => console.log(x)); source.next('a'); source.next('b'); source.next('c'); source.complete(); // Results in: // a // false // b // c
  • 24. 10th Operator • There are more than 50 operators are there. • You can look at those operators at - https://rxjs- dev.firebaseapp.com/api/operators/ • Even you can build your own operators!!
  • 25. Q&A
  • 26. Thank you! • Email: jalpesh@futurestacksolution.com • Blog: https://www.dotnetjalps.com • YouTube: http://bit.ly/codewithjv • GitHub: https://github.com/jalpeshvadgama • Twitter: @Jalpesh