d6f377283838ae5b074d5d5dee932080edfbce0c667ffda94e3682ffab0201f48f3db29e846237b6c1a6a36f6cb304c16383a7e410d48a0d6f2c3370f9194f 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { 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. */
  60. export declare function refCount<T>(): MonoTypeOperatorFunction<T>;
  61. //# sourceMappingURL=refCount.d.ts.map