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

More Related Content

What's hot (20)

RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Express JS
Express JSExpress JS
Express JS
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 

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

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

More from 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
 

More from 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...
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 

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