Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

TapObserver

An extension to the Observer interface used only by the tap operator.

It provides a useful set of callbacks a user can register to do side-effects in cases other than what the usual Observer callbacks are ({@link guide/glossary-and-semantics#next | next}, {@link guide/glossary-and-semantics#error | error} and/or {@link guide/glossary-and-semantics#complete | complete}).

Example

import { fromEvent, switchMap, tap, interval, take } from 'rxjs';

const source$ = fromEvent(document, 'click');
const result$ = source$.pipe(
  switchMap((_, i) => i % 2 === 0
    ? fromEvent(document, 'mousemove').pipe(
        tap({
          subscribe: () => console.log('Subscribed to the mouse move events after click #' + i),
          unsubscribe: () => console.log('Mouse move events #' + i + ' unsubscribed'),
          finalize: () => console.log('Mouse move events #' + i + ' finalized')
        })
      )
    : interval(1_000).pipe(
        take(5),
        tap({
          subscribe: () => console.log('Subscribed to the 1-second interval events after click #' + i),
          unsubscribe: () => console.log('1-second interval events #' + i + ' unsubscribed'),
          finalize: () => console.log('1-second interval events #' + i + ' finalized')
        })
      )
  )
);

const subscription = result$.subscribe({
  next: console.log
});

setTimeout(() => {
  console.log('Unsubscribe after 60 seconds');
  subscription.unsubscribe();
}, 60_000);
interface TapObserver <T> extends Observer<T> {
finalize: () => void;
subscribe: () => void;
unsubscribe: () => void;
}

§Type Parameters

§Extends

§Properties

§
finalize: () => void
[src]

The callback that tap operator invokes when any kind of {@link guide/glossary-and-semantics#finalization | finalization} happens - either when the source Observable errors or completes or when it gets explicitly unsubscribed by the user. There is no difference in using this callback or the finalize operator, but if you're already using tap operator, you can use this callback instead. You'd get the same result in either case.

§
subscribe: () => void
[src]

The callback that tap operator invokes at the moment when the source Observable gets subscribed to.

§
unsubscribe: () => void
[src]

The callback that tap operator invokes when an explicit {@link guide/glossary-and-semantics#unsubscription | unsubscribe} happens. It won't get invoked on error or complete events.