O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subscribing to changes (Observer)

To listen to data on an observable, we must call the subscribe() method. This method returns a subscription, which we can use later to stop reacting to the incoming data if we are no longer interested in it.

The subscribe() method of observables has the following signature:

observable.subscribe(onNext,onError,onCompleted); 

All parameters are optional and can be omitted if we are not interested in this type of event:

  • onNext: This is a function to be called every time new data is propagated through the observable
  • onError: This is a function to be called every time an error occurs in the observable
  • onCompleted: This is a function to be called when the observable is completed

The easiest way to subscribe ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required