Subtheme of barrio
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
7.5 KiB

{"version":3,"file":"multicast.js","sourceRoot":"","sources":["../../src/operator/multicast.ts"],"names":[],"mappings":";AAGA,0BAAyC,wBAAwB,CAAC,CAAA;AAOlE,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6FG;AACH,mBAAqD,uBAAwD,EAC7E,QAAmD;IACjF,MAAM,CAAC,qBAAW,CAAM,uBAAuB,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAHe,iBAAS,YAGxB,CAAA","sourcesContent":["import { Subject } from '../Subject';\nimport { Observable } from '../Observable';\nimport { ConnectableObservable } from '../observable/ConnectableObservable';\nimport { multicast as higherOrder } from '../operators/multicast';\nimport { FactoryOrValue, MonoTypeOperatorFunction, OperatorFunction } from '../interfaces';\n\n/* tslint:disable:max-line-length */\nexport function multicast<T>(this: Observable<T>, subjectOrSubjectFactory: FactoryOrValue<Subject<T>>): ConnectableObservable<T>;\nexport function multicast<T>(SubjectFactory: (this: Observable<T>) => Subject<T>, selector?: MonoTypeOperatorFunction<T>): Observable<T>;\nexport function multicast<T, R>(SubjectFactory: (this: Observable<T>) => Subject<T>, selector?: OperatorFunction<T, R>): Observable<R>;\n/* tslint:enable:max-line-length */\n\n/**\n * Allows source Observable to be subscribed only once with a Subject of choice,\n * while still sharing its values between multiple subscribers.\n *\n * <span class=\"informal\">Subscribe to Observable once, but send its values to multiple subscribers.</span>\n *\n * <img src=\"./img/multicast.png\" width=\"100%\">\n *\n * `multicast` is an operator that works in two modes.\n *\n * In the first mode you provide a single argument to it, which can be either an initialized Subject or a Subject\n * factory. As a result you will get a special kind of an Observable - a {@link ConnectableObservable}. It can be\n * subscribed multiple times, just as regular Observable, but it won't subscribe to the source Observable at that\n * moment. It will do it only if you call its `connect` method. This means you can essentially control by hand, when\n * source Observable will be actually subscribed. What is more, ConnectableObservable will share this one subscription\n * between all of its subscribers. This means that, for example, `ajax` Observable will only send a request once,\n * even though usually it would send a request per every subscriber. Since it sends a request at the moment of\n * subscription, here request would be sent when the `connect` method of a ConnectableObservable is called.\n *\n * The most common pattern of using ConnectableObservable is calling `connect` when the first consumer subscribes,\n * keeping the subscription alive while several consumers come and go and finally unsubscribing from the source\n * Observable, when the last consumer unsubscribes. To not implement that logic over and over again,\n * ConnectableObservable has a special operator, `refCount`. When called, it returns an Observable, which will count\n * the number of consumers subscribed to it and keep ConnectableObservable connected as long as there is at least\n * one consumer. So if you don't actually need to decide yourself when to connect and disconnect a\n * ConnectableObservable, use `refCount`.\n *\n * The second mode is invoked by calling `multicast` with an additional, second argument - selector function.\n * This function accepts an Observable - which basically mirrors the source Observable - and returns Observable\n * as well, which should be the input stream modified by any operators you want. Note that in this\n * mode you cannot provide initialized Subject as a first argument - it has to be a Subject factory. If\n * you provide selector function, `multicast` returns just a regular Observable, instead of ConnectableObservable.\n * Thus, as usual, each subscription to this stream triggers subscription to the source Observable. However,\n * if inside the selector function you subscribe to the input Observable multiple times, actual source stream\n * will be subscribed only once. So if you have a chain of operators that use some Observable many times,\n * but you want to subscribe to that Observable only once, this is the mode you would use.\n *\n * Subject provided as a first parameter of `multicast` is used as a proxy for the single subscription to the\n * source Observable. It means that all values from the source stream go through that Subject. Thus, if a Subject\n * has some special properties, Observable returned by `multicast` will have them as well. If you want to use\n * `multicast` with a Subject that is one of the ones included in RxJS by default - {@link Subject},\n * {@link AsyncSubject}, {@link BehaviorSubject}, or {@link ReplaySubject} - simply use {@link publish},\n * {@link publishLast}, {@link publishBehavior} or {@link publishReplay} respectively. These are actually\n * just wrappers around `multicast`, with a specific Subject hardcoded inside.\n *\n * Also, if you use {@link publish} or {@link publishReplay} with a ConnectableObservables `refCount` operator,\n * you can simply use {@link share} and {@link shareReplay} respectively, which chain these two.\n *\n * @example <caption>Use ConnectableObservable</caption>\n * const seconds = Rx.Observable.interval(1000);\n * const connectableSeconds = seconds.multicast(new Subject());\n *\n * connectableSeconds.subscribe(value => console.log('first: ' + value));\n * connectableSeconds.subscribe(value => console.log('second: ' + value));\n *\n * // At this point still nothing happens, even though we subscribed twice.\n *\n * connectableSeconds.connect();\n *\n * // From now on `seconds` are being logged to the console,\n * // twice per every second. `seconds` Observable was however only subscribed once,\n * // so under the hood Observable.interval had only one clock started.\n *\n * @example <caption>Use selector</caption>\n * const seconds = Rx.Observable.interval(1000);\n *\n * seconds\n * .multicast(\n * () => new Subject(),\n * seconds => seconds.zip(seconds) // Usually zip would subscribe to `seconds` twice.\n * // Because we are inside selector, `seconds` is subscribed once,\n * ) // thus starting only one clock used internally by Observable.interval.\n * .subscribe();\n *\n * @see {@link publish}\n * @see {@link publishLast}\n * @see {@link publishBehavior}\n * @see {@link publishReplay}\n * @see {@link share}\n * @see {@link shareReplay}\n *\n * @param {Function|Subject} subjectOrSubjectFactory - Factory function to create an intermediate Subject through\n * which the source sequence's elements will be multicast to the selector function input Observable or\n * ConnectableObservable returned by the operator.\n * @param {Function} [selector] - Optional selector function that can use the input stream\n * as many times as needed, without causing multiple subscriptions to the source stream.\n * Subscribers to the input source will receive all notifications of the source from the\n * time of the subscription forward.\n * @return {Observable<T>|ConnectableObservable<T>} An Observable that emits the results of invoking the selector\n * on the source stream or a special {@link ConnectableObservable}, if selector was not provided.\n *\n * @method multicast\n * @owner Observable\n */\nexport function multicast<T, R>(this: Observable<T>, subjectOrSubjectFactory: Subject<T> | (() => Subject<T>),\n selector?: (source: Observable<T>) => Observable<R>): Observable<R> | ConnectableObservable<R> {\n return higherOrder(<any>subjectOrSubjectFactory, selector)(this);\n}\n"]}