Top 10 RxJs Operators in Angular

jalpesh07 1,935 views 26 slides Oct 31, 2019
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

This slides describes about Top 10 Rxjs Operators in Angular which can be quite useful in our day to day life


Slide Content

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:

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!

MergeMap operator The merge map operator is handy when the requirement is to merge response from two observables

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

Delay operator The Delay operator emits values after some delay

Retry operator if a source Observable emits an error, resubscribe to it in the hopes that it will complete without error

Zip operator Multiple observables emitting at alternate intervals

Distinct operator Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.

IsEmpty operator Emits false if the input observable emits any values, or emits true if the input observable completes without emitting any values.

10 th 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 : [email protected] Blog : https://www.dotnetjalps.com YouTube: http://bit.ly/codewithjv GitHub: https://github.com/jalpeshvadgama Twitter: @Jalpesh