tap
operator used to do side effect for every emission (next, complete and error)
we can pass a function to perform a side effect for
next
emissionor pass an
observer
to perform side effects for next, complete or error emission
next
emissionopen the inspector, you will see many logs because the observable has extra subscriptions
import { interval } from 'rxjs';
import { tap, take } from 'rxjs/operators';
const source$ = interval(1500).pipe(take(4));
const result$ = source$.pipe(
tap(i => console.log(`Example tap: ${i}`)),
);
observer
{next: () => {}, error: () => {}, complete: () => {}}
import { interval } from 'rxjs';
import { tap, take } from 'rxjs/operators';
const source$ = interval(1500).pipe(take(4));
const result$ = source$.pipe(
tap({
next: (i) => console.log(i),
error: (e) => console.error(e),
complete: () => console.warn('complete')
}),
);
Official Doc: rxjs.tap