- do / tap
- 签名:
do(nextOrObserver: function, error: function, complete: function): Observable
- 签名:
- Transparently perform actions or side-effects, such as logging.
- 透明地执行操作或副作用,比如打印日志。
- 示例
- 示例 1: 使用 do 输出日志
- 示例
- 其他资源
do / tap
签名: do(nextOrObserver: function, error: function, complete: function): Observable
Transparently perform actions or side-effects, such as logging.
透明地执行操作或副作用,比如打印日志。
If you are using as a pipeable operator, do is known as tap!

示例
示例 1: 使用 do 输出日志
( jsBin |
jsFiddle )
import { of } from 'rxjs/observable/of';import { tap, map } from 'rxjs/operators';const source = of(1, 2, 3, 4, 5);// 使用 tap 透明地打印 source 中的值const example = source.pipe(tap(val => console.log(`BEFORE MAP: ${val}`)),map(val => val + 10),tap(val => console.log(`AFTER MAP: ${val}`)));// 'tap' 并不转换值// 输出: 11...12...13...14...15const subscribe = example.subscribe(val => console.log(val));
其他资源
- do
- 官方文档 - 使用 do 打印流
- John Linquist - 工具操作符: do
- André Staltz
源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/do.ts
