1 | import { MonoTypeOperatorFunction, Observer } from '../types';
|
2 | /**
|
3 | * An extension to the {@link Observer} interface used only by the {@link tap} operator.
|
4 | *
|
5 | * It provides a useful set of callbacks a user can register to do side-effects in
|
6 | * cases other than what the usual {@link Observer} callbacks are
|
7 | * ({@link guide/glossary-and-semantics#next next},
|
8 | * {@link guide/glossary-and-semantics#error error} and/or
|
9 | * {@link guide/glossary-and-semantics#complete complete}).
|
10 | *
|
11 | * ## Example
|
12 | *
|
13 | * ```ts
|
14 | * import { fromEvent, switchMap, tap, interval, take } from 'rxjs';
|
15 | *
|
16 | * const source$ = fromEvent(document, 'click');
|
17 | * const result$ = source$.pipe(
|
18 | * switchMap((_, i) => i % 2 === 0
|
19 | * ? fromEvent(document, 'mousemove').pipe(
|
20 | * tap({
|
21 | * subscribe: () => console.log('Subscribed to the mouse move events after click #' + i),
|
22 | * unsubscribe: () => console.log('Mouse move events #' + i + ' unsubscribed'),
|
23 | * finalize: () => console.log('Mouse move events #' + i + ' finalized')
|
24 | * })
|
25 | * )
|
26 | * : interval(1_000).pipe(
|
27 | * take(5),
|
28 | * tap({
|
29 | * subscribe: () => console.log('Subscribed to the 1-second interval events after click #' + i),
|
30 | * unsubscribe: () => console.log('1-second interval events #' + i + ' unsubscribed'),
|
31 | * finalize: () => console.log('1-second interval events #' + i + ' finalized')
|
32 | * })
|
33 | * )
|
34 | * )
|
35 | * );
|
36 | *
|
37 | * const subscription = result$.subscribe({
|
38 | * next: console.log
|
39 | * });
|
40 | *
|
41 | * setTimeout(() => {
|
42 | * console.log('Unsubscribe after 60 seconds');
|
43 | * subscription.unsubscribe();
|
44 | * }, 60_000);
|
45 | * ```
|
46 | */
|
47 | export interface TapObserver<T> extends Observer<T> {
|
48 | /**
|
49 | * The callback that `tap` operator invokes at the moment when the source Observable
|
50 | * gets subscribed to.
|
51 | */
|
52 | subscribe: () => void;
|
53 | /**
|
54 | * The callback that `tap` operator invokes when an explicit
|
55 | * {@link guide/glossary-and-semantics#unsubscription unsubscribe} happens. It won't get invoked on
|
56 | * `error` or `complete` events.
|
57 | */
|
58 | unsubscribe: () => void;
|
59 | /**
|
60 | * The callback that `tap` operator invokes when any kind of
|
61 | * {@link guide/glossary-and-semantics#finalization finalization} happens - either when
|
62 | * the source Observable `error`s or `complete`s or when it gets explicitly unsubscribed
|
63 | * by the user. There is no difference in using this callback or the {@link finalize}
|
64 | * operator, but if you're already using `tap` operator, you can use this callback
|
65 | * instead. You'd get the same result in either case.
|
66 | */
|
67 | finalize: () => void;
|
68 | }
|
69 | export declare function tap<T>(observerOrNext?: Partial<TapObserver<T>> | ((value: T) => void)): MonoTypeOperatorFunction<T>;
|
70 | /** @deprecated Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments */
|
71 | export declare function tap<T>(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): MonoTypeOperatorFunction<T>;
|
72 | //# sourceMappingURL=tap.d.ts.map |
\ | No newline at end of file |