DEV Community

Cover image for Observables... why?
Niharika Pujari
Niharika Pujari

Posted on

Observables... why?

Many times in the front end realm, while using angular framework we come across "Let's use an observable". OH! Well ok, but why?

Observables are used to fetch data Asynchronously and we can use their return values in a continuous sequence (multiple times) when executed.

  • By default, they are lazy as it emits values when time progresses.

  • They offer a lot of operators which simplifies the coding effort.

  • Can be cancelled using unsubscribe method anytime.

  • RXJS operators: You have many pipe operators majorly map, filter, switchMap, combineLatest, etc. to transform observable data before subscribing.

  • Subscribe method allows us to have a centralized and predictable error handling.

  • One operator retry can be used to retry whenever needed, also if we need to retry the observable based on some conditions retryWhen can be used.

Reference:
RXJS: https://rxjs.dev/guide/overview
List of operators along with their interactive diagrams: https://rxmarbles.com/

Top comments (0)