The Magic of RxJs Operators

What is RxJS?

RxJs is a framework for reactive programming that makes use of Observables, making it really easy to write asynchronous code. RxJs is the official library used by Angular to handle reactivity, converting pull operations for call-backs into Observables. When working with RxJS, everything revolves around the Observable.
 
What is Observable?

In RxJS, an Observable is what we can use to listen aka subscribe to new changes that are emitted by an Observer.
 
Observables are the foundation of reactive programming in RxJS and operators are the best way to consume or utilise them.

What is Operators?

In RxJS, you can think of Operators as a way to manipulate the data coming from a Subject (or Observer) before it's sent to an Observable. They are methods you can use on Observables and subjects to manipulate, filter or change the Observable in a specified manner into a new Observable. In simple words, the purpose of Operators are to allow you to perform operations on your logic/code.

It is important to note that operators do not change the initial Observable, they just edit it and output an entirely new Observable.

Types of Operators

According to the official RxJS documentation, there are two types of operators.

1. Pipe-able operators: These are operators that can be piped to existing Observables using the pipe syntax. They are called on existing Observables and they do not change the Observable instance, they return a new Observable with a subscribe method based on the initial Observable.

2. Creation operators: These operators, on the other hand, create an Observable with either a pre-defined behaviour or by joining more than one Observable together. They can be referred to as standalone methods that create new Observables.

Categories of operators

Operators can be classified into various categories, some of these are:

1. Creation,
2. Transformation,
3. Filtering,
4. Joining,
5. Multicasting,
6. Error handling and
7. Utility
Categories of operators
Fig: Categories of Operators



Comments

Popular Posts