do

signature: do(nextOrObserver: function, error: function, complete: function): Observable

Transparently perform actions or side-effects, such as logging.

Examples

Example 1: Logging with do

( jsBin | jsFiddle )

const source = Rx.Observable.of(1,2,3,4,5);
//transparently log values from source with 'do'
const example = source
  .do(val => console.log(`BEFORE MAP: ${val}`))
  .map(val => val + 10)
  .do(val => console.log(`AFTER MAP: ${val}`));
//'do' does not transform values
//output: 11...12...13...14...15
const subscribe = example.subscribe(val => console.log(val));

Additional Resources


:file_folder: Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/operator/do.ts

results matching ""

    No results matching ""