1 import { Observable } from '../Observable';
2 import { multicast } from './multicast';
3 import { refCount } from './refCount';
4 import { Subject } from '../Subject';
6 import { MonoTypeOperatorFunction } from '../types';
8 function shareSubjectFactory() {
13 * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one
14 * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will
15 * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`.
16 * This is an alias for `multicast(() => new Subject()), refCount()`.
20 * @return {Observable<T>} An Observable that upon connection causes the source Observable to emit items to its Observers.
24 export function share<T>(): MonoTypeOperatorFunction<T> {
25 return (source: Observable<T>) => refCount()(multicast(shareSubjectFactory)(source)) as Observable<T>;