| 1 |
import { Observable } from '../Observable'; |
| 2 |
import { ReplaySubject } from '../ReplaySubject'; |
| 3 |
import { multicast } from './multicast'; |
| 4 |
import { MonoTypeOperatorFunction, OperatorFunction, TimestampProvider, ObservableInput, ObservedValueOf } from '../types'; |
| 5 |
import { isFunction } from '../util/isFunction'; |
| 6 |
|
| 7 |
/** |
| 8 |
* Creates a {@link ConnectableObservable} that uses a {@link ReplaySubject} |
| 9 |
* internally. |
| 10 |
* |
| 11 |
* @param bufferSize The buffer size for the underlying {@link ReplaySubject}. |
| 12 |
* @param windowTime The window time for the underlying {@link ReplaySubject}. |
| 13 |
* @param timestampProvider The timestamp provider for the underlying {@link ReplaySubject}. |
| 14 |
* @deprecated Will be removed in v8. To create a connectable observable that uses a |
| 15 |
* {@link ReplaySubject} under the hood, use {@link connectable}. |
| 16 |
* `source.pipe(publishReplay(size, time, scheduler))` is equivalent to |
| 17 |
* `connectable(source, { connector: () => new ReplaySubject(size, time, scheduler), resetOnDisconnect: false })`. |
| 18 |
* If you're using {@link refCount} after `publishReplay`, use the {@link share} operator instead. |
| 19 |
* `publishReplay(size, time, scheduler), refCount()` is equivalent to |
| 20 |
* `share({ connector: () => new ReplaySubject(size, time, scheduler), resetOnError: false, resetOnComplete: false, resetOnRefCountZero: false })`. |
| 21 |
* Details: https://rxjs.dev/deprecations/multicasting |
| 22 |
*/ |
| 23 |
export function publishReplay<T>( |
| 24 |
bufferSize?: number, |
| 25 |
windowTime?: number, |
| 26 |
timestampProvider?: TimestampProvider |
| 27 |
): MonoTypeOperatorFunction<T>; |
| 28 |
|
| 29 |
/** |
| 30 |
* Creates an observable, that when subscribed to, will create a {@link ReplaySubject}, |
| 31 |
* and pass an observable from it (using [asObservable](api/index/class/Subject#asObservable)) to |
| 32 |
* the `selector` function, which then returns an observable that is subscribed to before |
| 33 |
* "connecting" the source to the internal `ReplaySubject`. |
| 34 |
* |
| 35 |
* Since this is deprecated, for additional details see the documentation for {@link connect}. |
| 36 |
* |
| 37 |
* @param bufferSize The buffer size for the underlying {@link ReplaySubject}. |
| 38 |
* @param windowTime The window time for the underlying {@link ReplaySubject}. |
| 39 |
* @param selector A function used to setup the multicast. |
| 40 |
* @param timestampProvider The timestamp provider for the underlying {@link ReplaySubject}. |
| 41 |
* @deprecated Will be removed in v8. Use the {@link connect} operator instead. |
| 42 |
* `source.pipe(publishReplay(size, window, selector, scheduler))` is equivalent to |
| 43 |
* `source.pipe(connect(selector, { connector: () => new ReplaySubject(size, window, scheduler) }))`. |
| 44 |
* Details: https://rxjs.dev/deprecations/multicasting |
| 45 |
*/ |
| 46 |
export function publishReplay<T, O extends ObservableInput<any>>( |
| 47 |
bufferSize: number | undefined, |
| 48 |
windowTime: number | undefined, |
| 49 |
selector: (shared: Observable<T>) => O, |
| 50 |
timestampProvider?: TimestampProvider |
| 51 |
): OperatorFunction<T, ObservedValueOf<O>>; |
| 52 |
|
| 53 |
/** |
| 54 |
* Creates a {@link ConnectableObservable} that uses a {@link ReplaySubject} |
| 55 |
* internally. |
| 56 |
* |
| 57 |
* @param bufferSize The buffer size for the underlying {@link ReplaySubject}. |
| 58 |
* @param windowTime The window time for the underlying {@link ReplaySubject}. |
| 59 |
* @param selector Passing `undefined` here determines that this operator will return a {@link ConnectableObservable}. |
| 60 |
* @param timestampProvider The timestamp provider for the underlying {@link ReplaySubject}. |
| 61 |
* @deprecated Will be removed in v8. To create a connectable observable that uses a |
| 62 |
* {@link ReplaySubject} under the hood, use {@link connectable}. |
| 63 |
* `source.pipe(publishReplay(size, time, scheduler))` is equivalent to |
| 64 |
* `connectable(source, { connector: () => new ReplaySubject(size, time, scheduler), resetOnDisconnect: false })`. |
| 65 |
* If you're using {@link refCount} after `publishReplay`, use the {@link share} operator instead. |
| 66 |
* `publishReplay(size, time, scheduler), refCount()` is equivalent to |
| 67 |
* `share({ connector: () => new ReplaySubject(size, time, scheduler), resetOnError: false, resetOnComplete: false, resetOnRefCountZero: false })`. |
| 68 |
* Details: https://rxjs.dev/deprecations/multicasting |
| 69 |
*/ |
| 70 |
export function publishReplay<T, O extends ObservableInput<any>>( |
| 71 |
bufferSize: number | undefined, |
| 72 |
windowTime: number | undefined, |
| 73 |
selector: undefined, |
| 74 |
timestampProvider: TimestampProvider |
| 75 |
): OperatorFunction<T, ObservedValueOf<O>>; |
| 76 |
|
| 77 |
/** |
| 78 |
* @deprecated Will be removed in v8. Use the {@link connectable} observable, the {@link connect} operator or the |
| 79 |
* {@link share} operator instead. See the overloads below for equivalent replacement examples of this operator's |
| 80 |
* behaviors. |
| 81 |
* Details: https://rxjs.dev/deprecations/multicasting |
| 82 |
*/ |
| 83 |
export function publishReplay<T, R>( |
| 84 |
bufferSize?: number, |
| 85 |
windowTime?: number, |
| 86 |
selectorOrScheduler?: TimestampProvider | OperatorFunction<T, R>, |
| 87 |
timestampProvider?: TimestampProvider |
| 88 |
) { |
| 89 |
if (selectorOrScheduler && !isFunction(selectorOrScheduler)) { |
| 90 |
timestampProvider = selectorOrScheduler; |
| 91 |
} |
| 92 |
const selector = isFunction(selectorOrScheduler) ? selectorOrScheduler : undefined; |
| 93 |
// Note, we're passing `selector!` here, because at runtime, `undefined` is an acceptable argument |
| 94 |
// but it makes our TypeScript signature for `multicast` unhappy (as it should, because it's gross). |
| 95 |
return (source: Observable<T>) => multicast(new ReplaySubject<T>(bufferSize, windowTime, timestampProvider), selector!)(source); |
| 96 |
} |