1 | import { Observable } from '../Observable';
|
---|
2 | import { ReplaySubject } from '../ReplaySubject';
|
---|
3 | import { multicast } from './multicast';
|
---|
4 | import { ConnectableObservable } from '../observable/ConnectableObservable';
|
---|
5 | import { UnaryFunction, MonoTypeOperatorFunction, OperatorFunction, SchedulerLike, ObservableInput, ObservedValueOf } from '../types';
|
---|
6 |
|
---|
7 | /* tslint:disable:max-line-length */
|
---|
8 | export function publishReplay<T>(bufferSize?: number, windowTime?: number, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
|
---|
9 | export function publishReplay<T, O extends ObservableInput<any>>(bufferSize?: number, windowTime?: number, selector?: (shared: Observable<T>) => O, scheduler?: SchedulerLike): OperatorFunction<T, ObservedValueOf<O>>;
|
---|
10 | /* tslint:enable:max-line-length */
|
---|
11 |
|
---|
12 | export function publishReplay<T, R>(bufferSize?: number,
|
---|
13 | windowTime?: number,
|
---|
14 | selectorOrScheduler?: SchedulerLike | OperatorFunction<T, R>,
|
---|
15 | scheduler?: SchedulerLike): UnaryFunction<Observable<T>, ConnectableObservable<R>> {
|
---|
16 |
|
---|
17 | if (selectorOrScheduler && typeof selectorOrScheduler !== 'function') {
|
---|
18 | scheduler = selectorOrScheduler;
|
---|
19 | }
|
---|
20 |
|
---|
21 | const selector = typeof selectorOrScheduler === 'function' ? selectorOrScheduler : undefined;
|
---|
22 | const subject = new ReplaySubject<T>(bufferSize, windowTime, scheduler);
|
---|
23 |
|
---|
24 | return (source: Observable<T>) => multicast(() => subject, selector)(source) as ConnectableObservable<R>;
|
---|
25 | }
|
---|