An Introduction to Observables in RxJS

An Introduction to Observables in RxJS

In this post, we will learn about one of the most useful RXJS concept Observable.

So, let's get started...

What is Observable?

Observables are the most important topic of RXJS.

Observables were introduced in RXJS.

An Observable is just a function with a few special characteristics.

For example, if you subscribe to any youtube channel you will get notified every time this channel uploads a new video.

The Observables are lazy, which means they don't execute until they subscribed.

What is an observer?

We need to subscribe to observable to use it, which is called observer. 

When an Observable produces values, it then informs the observer, calling .next() when a new value was successfully captured and .error() when an error occurs.

When we subscribe to an Observable, it will keep passing any values to an observer until one of two things happens. Either the producer says there are no more values to be sent, in which case it will call .complete() on our observer, or we (as the "consumers") decide we are no longer interested in the values and we unsubscribe.

What is an operator?

An operator is a function that creates a new observable based on the input observed.

The purpose of the operator is to modify or filter originally emitted values in the way we need for the project tasks.

We can say Operators are basically pure functions, that transform information into the observables stream.

The operator always creates new observables, based on the current observables.

we can also use multiple operators in one method using the pipe() method which is also known as a Channing of Operators.

Operators are by nature immutable.

Now in the very next article, we will learn about how we can create custom observable in rxjs.

Conclusion:

Do let me know If you face any difficulties please feel free to comment below we love to help you.

If you have any feedback suggestion then please inform us by commenting.

Don’t forget to share this tutorial with your friends on Facebook and Twitter

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

You might also like

Leave a Comment