Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | import { Observable } from '../Observable';
|
---|
| 2 | import { multicast } from './multicast';
|
---|
| 3 | import { refCount } from './refCount';
|
---|
| 4 | import { Subject } from '../Subject';
|
---|
| 5 |
|
---|
| 6 | import { MonoTypeOperatorFunction } from '../types';
|
---|
| 7 |
|
---|
| 8 | function 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 | */
|
---|
| 24 | export 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.