Learnitweb

RxJS operators

1. Introduction

RxJS is very convenient to use because it provides lot of operators. RxJS operators are very helpful in working with asynchronous data.

RxJS operators are actually functions. There are two types of operators:

  1. Pipeable Operators
  2. Creation operators

2. Pipeable Operators

These operators can be piped to Observables. The syntax of pipeable operator is:

observableInstance.pipe(operator())

Following are important points about pipeable operators:

  • A pipeable operator is a function that takes an Observable as its input and produces an Observable.
  • A pipeable operator does not change existing Observable.
  • A pipeable operator returns a new Observable whose subscription logic is based on first Observable.
  • Subscribing to the Observable returned by pipeable operator will also subscribe to the input Observable.
  • Due to above mentioned points, a pipeable operator is essentially a pure function.
  • filter() is an example of Pipeable operator.

3. Creation Operators

A creator operator is a function used to create a new Observable. A creator operator can create an Observable with some predefined behavior or by joining observables.

An example of a creation operator is interval function. It takes a number as an input argument and produces an Observable as output.

import { interval } from 'rxjs';
const observable = interval(1000); // 1000 milliseconds

4. Categories of operators

4.1 Creation operators

ajaxbindCallbackbindNodeCallback
deferemptyfrom
fromEventfromEventPatterngenerate
intervalofrange
throwErrortimeriif

4.2 Join Creation Operators

These are creation operators which have join functionality.

combineLatestconcatforkJoin
mergepartitionrace
zip

4.3 Transformation Operators

bufferbufferCountbufferTime
bufferTogglebufferWhenconcatMap
concatMapToexhaustexhaustMap
expandgroupBymap
mapTomergeMapmergeMapTo
mergeScanpairwisepartition
pluckscanswitchScan
switchMapswitchMapTowindow
windowCountwindowTimewindowToggle
windowWhen

4.3 Filtering operators

auditauditTimedebounce
debounceTimedistinctdistinctUntilChanged
distinctUntilKeyChangedelementAtfilter
firstignoreElementslast
samplesampleTimesingle
skipskipLastskipUntil
skipWhiletaketakeLast
takeUntiltakeWhilethrottle
throttleTime

4.4 Join Operators

combineLatestAllconcatAllexhaustAll
mergeAllswitchAllstartWith
withLatestFrom

4.5 Multicasting Operators

multicastpublishpublishBehavior
publishLastpublishReplayshare

4.6 Error Handling Operators

catchErrorretryretryWhen

4.7 Utility Operators

tapdelaydelayWhen
dematerializematerializeobserveOn
subscribeOntimeIntervaltimestamp
timeouttimeoutWithtoArray

4.8 Conditional and Boolean Operators

defaultIfEmptyeveryfind
findIndexisEmpty

4.9 Mathematical and Aggregate Operators

countmaxmin
reduce