Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
93 lines (77 loc) · 2.76 KB

doonnext.md

File metadata and controls

93 lines (77 loc) · 2.76 KB

Rx.Observable.prototype.doOnNext(onNext, [thisArg])

Rx.Observable.prototype.tapOnNext(onNext, [thisArg])

Invokes an action for each element of the observable sequence.

This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.

Arguments

  1. onNext (Function): Function to invoke for each element in the observable sequence.
  2. [thisArg] (Any): Object to use as this when executing callback.

Returns

(Observable): The source sequence with the side-effecting behavior applied.

Example

/* Using a function */
var source = Rx.Observable.range(0, 3)
  .doOnNext(
    function () { console.log('Do Next: %s', x); }
  );

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Do Next: 0
// => Next: 0
// => Do Next: 1
// => Next: 1
// => Do Next: 2
// => Next: 2
// => Completed

/* Using a thisArg */

var source = Rx.Observable.range(0, 3)
  .doOnNext(
    function () { this.log('Do Next: %s', x); },
    console
  );

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Do Next: 0
// => Next: 0
// => Do Next: 1
// => Next: 1
// => Do Next: 2
// => Next: 2
// => Completed

Location

File:

Dist:

NPM Packages:

NuGet Packages:

Unit Tests: