7ef1c46028556313f927d88707bed1f998e9f3cc08655eec40fbeb4fecc5e0cfb7fe052fe01deaf1aa888e87b56003e1b6ccd10d60b0be3d86dcf5532f9c11 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { Subject } from '../Subject';
  2. import { Observable } from '../Observable';
  3. import { ConnectableObservable } from '../observable/ConnectableObservable';
  4. import { OperatorFunction, UnaryFunction, ObservedValueOf, ObservableInput } from '../types';
  5. import { isFunction } from '../util/isFunction';
  6. import { connect } from './connect';
  7. /**
  8. * An operator that creates a {@link ConnectableObservable}, that when connected,
  9. * with the `connect` method, will use the provided subject to multicast the values
  10. * from the source to all consumers.
  11. *
  12. * @param subject The subject to multicast through.
  13. * @return A function that returns a {@link ConnectableObservable}
  14. * @deprecated Will be removed in v8. To create a connectable observable, use {@link connectable}.
  15. * If you're using {@link refCount} after `multicast`, use the {@link share} operator instead.
  16. * `multicast(subject), refCount()` is equivalent to
  17. * `share({ connector: () => subject, resetOnError: false, resetOnComplete: false, resetOnRefCountZero: false })`.
  18. * Details: https://rxjs.dev/deprecations/multicasting
  19. */
  20. export function multicast<T>(subject: Subject<T>): UnaryFunction<Observable<T>, ConnectableObservable<T>>;
  21. /**
  22. * Because this is deprecated in favor of the {@link connect} operator, and was otherwise poorly documented,
  23. * rather than duplicate the effort of documenting the same behavior, please see documentation for the
  24. * {@link connect} operator.
  25. *
  26. * @param subject The subject used to multicast.
  27. * @param selector A setup function to setup the multicast
  28. * @return A function that returns an observable that mirrors the observable returned by the selector.
  29. * @deprecated Will be removed in v8. Use the {@link connect} operator instead.
  30. * `multicast(subject, selector)` is equivalent to
  31. * `connect(selector, { connector: () => subject })`.
  32. * Details: https://rxjs.dev/deprecations/multicasting
  33. */
  34. export function multicast<T, O extends ObservableInput<any>>(
  35. subject: Subject<T>,
  36. selector: (shared: Observable<T>) => O
  37. ): OperatorFunction<T, ObservedValueOf<O>>;
  38. /**
  39. * An operator that creates a {@link ConnectableObservable}, that when connected,
  40. * with the `connect` method, will use the provided subject to multicast the values
  41. * from the source to all consumers.
  42. *
  43. * @param subjectFactory A factory that will be called to create the subject. Passing a function here
  44. * will cause the underlying subject to be "reset" on error, completion, or refCounted unsubscription of
  45. * the source.
  46. * @return A function that returns a {@link ConnectableObservable}
  47. * @deprecated Will be removed in v8. To create a connectable observable, use {@link connectable}.
  48. * If you're using {@link refCount} after `multicast`, use the {@link share} operator instead.
  49. * `multicast(() => new BehaviorSubject('test')), refCount()` is equivalent to
  50. * `share({ connector: () => new BehaviorSubject('test') })`.
  51. * Details: https://rxjs.dev/deprecations/multicasting
  52. */
  53. export function multicast<T>(subjectFactory: () => Subject<T>): UnaryFunction<Observable<T>, ConnectableObservable<T>>;
  54. /**
  55. * Because this is deprecated in favor of the {@link connect} operator, and was otherwise poorly documented,
  56. * rather than duplicate the effort of documenting the same behavior, please see documentation for the
  57. * {@link connect} operator.
  58. *
  59. * @param subjectFactory A factory that creates the subject used to multicast.
  60. * @param selector A function to setup the multicast and select the output.
  61. * @return A function that returns an observable that mirrors the observable returned by the selector.
  62. * @deprecated Will be removed in v8. Use the {@link connect} operator instead.
  63. * `multicast(subjectFactory, selector)` is equivalent to
  64. * `connect(selector, { connector: subjectFactory })`.
  65. * Details: https://rxjs.dev/deprecations/multicasting
  66. */
  67. export function multicast<T, O extends ObservableInput<any>>(
  68. subjectFactory: () => Subject<T>,
  69. selector: (shared: Observable<T>) => O
  70. ): OperatorFunction<T, ObservedValueOf<O>>;
  71. /**
  72. * @deprecated Will be removed in v8. Use the {@link connectable} observable, the {@link connect} operator or the
  73. * {@link share} operator instead. See the overloads below for equivalent replacement examples of this operator's
  74. * behaviors.
  75. * Details: https://rxjs.dev/deprecations/multicasting
  76. */
  77. export function multicast<T, R>(
  78. subjectOrSubjectFactory: Subject<T> | (() => Subject<T>),
  79. selector?: (source: Observable<T>) => Observable<R>
  80. ): OperatorFunction<T, R> {
  81. const subjectFactory = isFunction(subjectOrSubjectFactory) ? subjectOrSubjectFactory : () => subjectOrSubjectFactory;
  82. if (isFunction(selector)) {
  83. // If a selector function is provided, then we're a "normal" operator that isn't
  84. // going to return a ConnectableObservable. We can use `connect` to do what we
  85. // need to do.
  86. return connect(selector, {
  87. connector: subjectFactory,
  88. });
  89. }
  90. return (source: Observable<T>) => new ConnectableObservable<any>(source, subjectFactory);
  91. }