1 import { Observable } from '../Observable';
2 import { Subject } from '../Subject';
3 import { multicast } from './multicast';
4 import { ConnectableObservable } from '../observable/ConnectableObservable';
5 import { MonoTypeOperatorFunction, OperatorFunction, UnaryFunction, ObservableInput, ObservedValueOf } from '../types';
7 /* tslint:disable:max-line-length */
8 export function publish<T>(): UnaryFunction<Observable<T>, ConnectableObservable<T>>;
9 export function publish<T, O extends ObservableInput<any>>(selector: (shared: Observable<T>) => O): OperatorFunction<T, ObservedValueOf<O>>;
10 export function publish<T>(selector: MonoTypeOperatorFunction<T>): MonoTypeOperatorFunction<T>;
11 /* tslint:enable:max-line-length */
14 * Returns a ConnectableObservable, which is a variety of Observable that waits until its connect method is called
15 * before it begins emitting items to those Observers that have subscribed to it.
17 * <span class="informal">Makes a cold Observable hot</span>
22 * Make source$ hot by applying publish operator, then merge each inner observable into a single one
25 * import { of, zip, interval, merge } from "rxjs";
26 * import { map, publish, tap } from "rxjs/operators";
28 * const source$ = zip(interval(2000), of(1, 2, 3, 4, 5, 6, 7, 8, 9)).pipe(
29 * map(values => values[1])
34 * publish(multicasted$ =>
36 * multicasted$.pipe(tap(x => console.log('Stream 1:', x))),
37 * multicasted$.pipe(tap(x => console.log('Stream 2:', x))),
38 * multicasted$.pipe(tap(x => console.log('Stream 3:', x))),
44 * // Results every two seconds
54 * @param {Function} [selector] - Optional selector function which can use the multicasted source sequence as many times
55 * as needed, without causing multiple subscriptions to the source sequence.
56 * Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
57 * @return A ConnectableObservable that upon connection causes the source Observable to emit items to its Observers.
63 export function publish<T, R>(selector?: OperatorFunction<T, R>): MonoTypeOperatorFunction<T> | OperatorFunction<T, R> {
65 multicast(() => new Subject<T>(), selector) :
66 multicast(new Subject<T>());