π‘ If you are using as a pipeable operator, do
is known as tap
!
ββββ
Example 1: Logging with 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...15const subscribe = example.subscribe(val => console.log(val));
Example 2: Using tap with object
( 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 completeconst 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β
β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/tap.tsβ