source: trip-planner-front/node_modules/rxjs/src/internal/operators/share.ts@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import { Observable } from '../Observable';
2import { multicast } from './multicast';
3import { refCount } from './refCount';
4import { Subject } from '../Subject';
5
6import { MonoTypeOperatorFunction } from '../types';
7
8function shareSubjectFactory() {
9 return new Subject();
10}
11
12/**
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()`.
17 *
18 * ![](share.png)
19 *
20 * @return {Observable<T>} An Observable that upon connection causes the source Observable to emit items to its Observers.
21 * @method share
22 * @owner Observable
23 */
24export function share<T>(): MonoTypeOperatorFunction<T> {
25 return (source: Observable<T>) => refCount()(multicast(shareSubjectFactory)(source)) as Observable<T>;
26}
Note: See TracBrowser for help on using the repository browser.