Rx.Observable.prototype.do(observer | [onNext], [onError], [onCompleted]), Rx.Observable.prototype.doAction(observer | [onNext], [onError], [onCompleted]), Rx.Observable.prototype.tap(observer | [onNext], [onError], [onCompleted])

do

Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination 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.

There is an alias to this method doAction for browsers <IE9 and tap as well.

参数

  1. [observer] (Observer): An observer to invoke for each element in the observable sequence.
  2. [onNext] (Function): Function to invoke for each element in the observable sequence.
  3. [onError] (Function): Function to invoke upon exceptional termination of the observable sequence. Used if only the first parameter is also a function.
  4. [oncompleted] (Function): Function to invoke upon graceful termination of the observable sequence. Used if only the first parameter is also a function.

返回值

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

Using a function

Using an observer