UNPKG

rxjs-es

Version:

Reactive Extensions for modern JavaScript

86 lines (85 loc) 3.97 kB
import { Observable } from '../Observable'; import { Scheduler } from '../Scheduler'; import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { Subscription } from '../Subscription'; import { OuterSubscriber } from '../OuterSubscriber'; import { InnerSubscriber } from '../InnerSubscriber'; /** * Recursively projects each source value to an Observable which is merged in * the output Observable. * * <span class="informal">It's similar to {@link mergeMap}, but applies the * projection function to every source value as well as every output value. * It's recursive.</span> * * <img src="./img/expand.png" width="100%"> * * Returns an Observable that emits items based on applying a function that you * supply to each item emitted by the source Observable, where that function * returns an Observable, and then merging those resulting Observables and * emitting the results of this merger. *Expand* will re-emit on the output * Observable every source value. Then, each output value is given to the * `project` function which returns an inner Observable to be merged on the * output Observable. Those output values resulting from the projection are also * given to the `project` function to produce new output values. This is how * *expand* behaves recursively. * * @example <caption>Start emitting the powers of two on every click, at most 10 of them</caption> * var clicks = Rx.Observable.fromEvent(document, 'click'); * var powersOfTwo = clicks * .mapTo(1) * .expand(x => Rx.Observable.of(2 * x).delay(1000)) * .take(10); * powersOfTwo.subscribe(x => console.log(x)); * * @see {@link mergeMap} * @see {@link mergeScan} * * @param {function(value: T, index: number) => Observable} project A function * that, when applied to an item emitted by the source or the output Observable, * returns an Observable. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input * Observables being subscribed to concurrently. * @param {Scheduler} [scheduler=null] The Scheduler to use for subscribing to * each projected inner Observable. * @return {Observable} An Observable that emits the source values and also * result of applying the projection function to each value emitted on the * output Observable and and merging the results of the Observables obtained * from this transformation. * @method expand * @owner Observable */ export declare function expand<T, R>(project: (value: T, index: number) => Observable<R>, concurrent?: number, scheduler?: Scheduler): Observable<R>; export interface ExpandSignature<T> { (project: (value: T, index: number) => Observable<T>, concurrent?: number, scheduler?: Scheduler): Observable<T>; <R>(project: (value: T, index: number) => Observable<R>, concurrent?: number, scheduler?: Scheduler): Observable<R>; } export declare class ExpandOperator<T, R> implements Operator<T, R> { private project; private concurrent; private scheduler; constructor(project: (value: T, index: number) => Observable<R>, concurrent: number, scheduler: Scheduler); call(subscriber: Subscriber<R>, source: any): any; } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ export declare class ExpandSubscriber<T, R> extends OuterSubscriber<T, R> { private project; private concurrent; private scheduler; private index; private active; private hasCompleted; private buffer; constructor(destination: Subscriber<R>, project: (value: T, index: number) => Observable<R>, concurrent: number, scheduler: Scheduler); private static dispatch<T, R>(arg); protected _next(value: any): void; private subscribeToProjection(result, value, index); protected _complete(): void; notifyNext(outerValue: T, innerValue: R, outerIndex: number, innerIndex: number, innerSub: InnerSubscriber<T, R>): void; notifyComplete(innerSub: Subscription): void; }