File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 11import { Observable } from '../Observable' ;
2- import { multicast } from './multicast' ;
3- import { Subject } from '../Subject' ;
4-
5- function shareSubjectFactory ( ) {
6- return new Subject ( ) ;
7- }
2+ import { share as higherOrder } from '../operators/share' ;
83
94/**
105 * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one
@@ -19,5 +14,5 @@ function shareSubjectFactory() {
1914 * @owner Observable
2015 */
2116export function share < T > ( this : Observable < T > ) : Observable < T > {
22- return multicast . call ( this , shareSubjectFactory ) . refCount ( ) ;
17+ return higherOrder ( ) ( this ) ;
2318} ;
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ export { sample } from './sample';
6262export { sampleTime } from './sampleTime' ;
6363export { scan } from './scan' ;
6464export { sequenceEqual } from './sequenceEqual' ;
65+ export { share } from './share' ;
6566export { subscribeOn } from './subscribeOn' ;
6667export { switchAll } from './switchAll' ;
6768export { switchMap } from './switchMap' ;
Original file line number Diff line number Diff line change 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 '../interfaces' ;
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 .publish().refCount().
17+ *
18+ * <img src="./img/share.png" width="100%">
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 ) ) ;
26+ } ;
You can’t perform that action at this time.
0 commit comments