Filtering with RxJS

1 min readApr 5, 2019

--

Filtering of observables can be done in different ways. These are the best options for some different use-cases.

The filter operator

In case the only thing you want to do is skip entire emits from the source observable based on a filter. the filter operator gets the job done perfectly.

The map operator

Most of the time filtering is done on the contents of an emitted value. To make this possible we can use the map operator and apply the filtering to the content of every emit of the source observable.

The combine operator

The previous examples all had static filters, as this is not always the case filtering can also be done with a combination of the combine operator and the map operator. This can be done by making an observable for the filter values and combining the source observable and the filter observable.

The advantage of this approach is that by updating either of the source observables (resultset or filter in this case) a new value is emitted with the result of the last emitted values of both.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response