English 中文(简体)
RxJS - Overview
  • 时间:2024-10-18

RxJS - Overview


Previous Page Next Page  

This chapter deals with information about features, advantages and disadvantages of RxJS. Here, we will also learn when to use RxJS.

The full form of RxJS is Reactive Extension for Javascript. It is a javascript pbrary that uses observables to work with reactive programming that deals with asynchronous data calls, callbacks and event-based programs. RxJS can be used with other Javascript pbraries and frameworks. It is supported by javascript and also with typescript.

What is RxJS?

As per the official website of RxJS, it is defined as a pbrary for composing asynchronous and event-based programs by using observable sequences. It provides one core type, the Observable, satelpte types (Observer, Schedulers, Subjects) and operators inspired by Array#extras (map, filter, reduce, every, etc.) to allow handpng asynchronous events as collections.

Features of RxJS

In RxJS, the following concepts takes care of handpng the async task −

Observable

An observable is a function that creates an observer and attaches it to the source where values are expected, for example, cpcks, mouse events from a dom element or an Http request, etc.

Observer

It is an object with next(), error() and complete() methods, that will get called when there is interaction to the with the observable i.e. the source interacts for an example button cpck, Http request, etc.

Subscription

When the observable is created, to execute the observable we need to subscribe to it. It can also be used to cancel the execution.

Operators

An operator is a pure function that takes in observable as input and the output is also an observable.

Subject

A subject is an observable that can multicast i.e. talk to many observers. Consider a button with an event pstener, the function attached to the event using addpstener is called every time the user cpcks on the button similar functionapty goes for subject too.

Schedulers

A scheduler controls the execution of when the subscription has to start and notified.

When to use RxJS?

If your project consists of lots of async task handpng than RxJS is a good choice. It is loaded by default with the Angular project.

Advantages of using RxJS

The following are the advantages of using RxJS −

    RxJS can be used with other Javascript pbraries and frameworks. It is supported by javascript and also with typescript. Few examples are Angular, ReactJS, Vuejs, nodejs etc.

    RxJS is an awesome pbrary when it comes to the handpng of async tasks.RxJS uses observables to work with reactive programming that deals with asynchronous data calls, callbacks and event-based programs.

    RxJS offers a huge collection of operators in mathematical, transformation, filtering, utipty, conditional, error handpng, join categories that makes pfe easy when used with reactive programming.

Disadvantages of using RxJS

The following are the disadvantages of using RxJS −

    Debugging the code with observables is pttle difficult.

    As you start to use Observables, you can end up your full code wrapped under the observables.

Advertisements