💡 If you are using as a pipeable operator, do
is known as tap
!
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { of } from 'rxjs';
import { tap, map } from 'rxjs/operators';
const source = of(1, 2, 3, 4, 5);
// transparently log values from source with 'tap'
const example = source.pipe(
tap(val => console.log(`BEFORE MAP: ${val}`)),
map(val => val + 10),
tap(val => console.log(`AFTER MAP: ${val}`))
);
//'tap' does not transform values
//output: 11...12...13...14...15
const subscribe = example.subscribe(val => console.log(val));
( StackBlitz)
// RxJS v6+
import { of } from 'rxjs';
import { tap, map } from 'rxjs/operators';
const source = of(1, 2, 3, 4, 5);
// tap also accepts an object map to log next, error, and complete
const example = source
.pipe(
map(val => val + 10),
tap({
next: val => {
// on next 11, etc.
console.log('on next', val);
},
error: error => {
console.log('on error', error.message);
},
complete: () => console.log('on complete')
})
)
// output: 11, 12, 13, 14, 15
.subscribe(val => console.log(val));
- Battleship Game
- Breakout Game
- Car Racing Game
- Catch The Dot Game
- Click Ninja Game
- Flappy Bird Game
- Horizontal Scroll Indicator
- Lockscreen
- Memory Game
- Mine Sweeper Game
- Platform Jumper Game
- Save Indicator
- Space Invaders Game
- Stop Watch
- Swipe To Refresh
- Tank Battle Game
- Tetris Game
- Type Ahead
- Uncover Image Game
- tap 📰 - Official docs
- Logging a stream with do 🎥 💵 - John Linquist
- Utility operator: do 🎥 💵 - André Staltz
- Build your own tap operator 🎥 - Kwinten Pisman
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/do.ts