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

The do() operator

This operator lets you execute arbitrary functions; it is really useful for debugging purposes, as you can log the data and have a better understanding of the workflow of your observable.

It has the following signature:

observable.do(execute); 

It receives only one parameter and it is mandatory:

  • execute: It is the function to be executed by this observable, it receives the value propagated by the observable as a parameter

An example usage of this operator can be seen in the following code:

Rx.Observable   .of('Joe DiMaggio','Friedrich Nietzsche','Nayara Neves','Marco Antonio')   .map((name)=>name.split(' ')[1])   .do((data)=>console.log('[DEBUG] Data after map operator: '+data))  .filter((name)=>name.indexOf('N')===0)  ...

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