UNPKG

2.53 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction } from '../types';
2/**
3 * Make a {@link ConnectableObservable} behave like a ordinary observable and automates the way
4 * you can connect to it.
5 *
6 * Internally it counts the subscriptions to the observable and subscribes (only once) to the source if
7 * the number of subscriptions is larger than 0. If the number of subscriptions is smaller than 1, it
8 * unsubscribes from the source. This way you can make sure that everything before the *published*
9 * refCount has only a single subscription independently of the number of subscribers to the target
10 * observable.
11 *
12 * Note that using the {@link share} operator is exactly the same as using the `multicast(() => new Subject())` operator
13 * (making the observable hot) and the *refCount* operator in a sequence.
14 *
15 * ![](refCount.png)
16 *
17 * ## Example
18 *
19 * In the following example there are two intervals turned into connectable observables
20 * by using the *publish* operator. The first one uses the *refCount* operator, the
21 * second one does not use it. You will notice that a connectable observable does nothing
22 * until you call its connect function.
23 *
24 * ```ts
25 * import { interval, tap, publish, refCount } from 'rxjs';
26 *
27 * // Turn the interval observable into a ConnectableObservable (hot)
28 * const refCountInterval = interval(400).pipe(
29 * tap(num => console.log(`refCount ${ num }`)),
30 * publish(),
31 * refCount()
32 * );
33 *
34 * const publishedInterval = interval(400).pipe(
35 * tap(num => console.log(`publish ${ num }`)),
36 * publish()
37 * );
38 *
39 * refCountInterval.subscribe();
40 * refCountInterval.subscribe();
41 * // 'refCount 0' -----> 'refCount 1' -----> etc
42 * // All subscriptions will receive the same value and the tap (and
43 * // every other operator) before the `publish` operator will be executed
44 * // only once per event independently of the number of subscriptions.
45 *
46 * publishedInterval.subscribe();
47 * // Nothing happens until you call .connect() on the observable.
48 * ```
49 *
50 * @return A function that returns an Observable that automates the connection
51 * to ConnectableObservable.
52 * @see {@link ConnectableObservable}
53 * @see {@link share}
54 * @see {@link publish}
55 * @deprecated Replaced with the {@link share} operator. How `share` is used
56 * will depend on the connectable observable you created just prior to the
57 * `refCount` operator.
58 * Details: https://rxjs.dev/deprecations/multicasting
59 */
60export declare function refCount<T>(): MonoTypeOperatorFunction<T>;
61//# sourceMappingURL=refCount.d.ts.map
\No newline at end of file