import { Operator } from '../Operator';
import { Subscriber } from '../Subscriber';
import { Subscription } from '../Subscription';
-import { OuterSubscriber } from '../OuterSubscriber';
-import { InnerSubscriber } from '../InnerSubscriber';
-import { subscribeToResult } from '../util/subscribeToResult';
import { MonoTypeOperatorFunction, OperatorFunction, ObservableInput, SchedulerLike } from '../types';
+import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
/* tslint:disable:max-line-length */
export function expand<T, R>(project: (value: T, index: number) => ObservableInput<R>, concurrent?: number, scheduler?: SchedulerLike): OperatorFunction<T, R>;
*/
export function expand<T, R>(project: (value: T, index: number) => ObservableInput<R>,
concurrent: number = Number.POSITIVE_INFINITY,
- scheduler: SchedulerLike = undefined): OperatorFunction<T, R> {
+ scheduler?: SchedulerLike): OperatorFunction<T, R> {
concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
return (source: Observable<T>) => source.lift(new ExpandOperator(project, concurrent, scheduler));
export class ExpandOperator<T, R> implements Operator<T, R> {
constructor(private project: (value: T, index: number) => ObservableInput<R>,
private concurrent: number,
- private scheduler: SchedulerLike) {
+ private scheduler?: SchedulerLike) {
}
call(subscriber: Subscriber<R>, source: any): any {
* @ignore
* @extends {Ignored}
*/
-export class ExpandSubscriber<T, R> extends OuterSubscriber<T, R> {
+export class ExpandSubscriber<T, R> extends SimpleOuterSubscriber<T, R> {
private index: number = 0;
private active: number = 0;
private hasCompleted: boolean = false;
- private buffer: any[];
+ private buffer?: any[];
constructor(destination: Subscriber<R>,
private project: (value: T, index: number) => ObservableInput<R>,
private concurrent: number,
- private scheduler: SchedulerLike) {
+ private scheduler?: SchedulerLike) {
super(destination);
if (concurrent < Number.POSITIVE_INFINITY) {
this.buffer = [];
const index = this.index++;
if (this.active < this.concurrent) {
- destination.next(value);
+ destination.next!(value);
try {
const { project } = this;
const result = project(value, index);
} else {
const state: DispatchArg<T, R> = { subscriber: this, result, value, index };
const destination = this.destination as Subscription;
- destination.add(this.scheduler.schedule<DispatchArg<T, R>>(ExpandSubscriber.dispatch, 0, state));
+ destination.add(this.scheduler.schedule<DispatchArg<T, R>>(ExpandSubscriber.dispatch as any, 0, state));
}
} catch (e) {
- destination.error(e);
+ destination.error!(e);
}
} else {
- this.buffer.push(value);
+ this.buffer!.push(value);
}
}
private subscribeToProjection(result: any, value: T, index: number): void {
this.active++;
const destination = this.destination as Subscription;
- destination.add(subscribeToResult<T, R>(this, result, value, index));
+ destination.add(innerSubscribe(result, new SimpleInnerSubscriber(this)));
}
protected _complete(): void {
this.hasCompleted = true;
if (this.hasCompleted && this.active === 0) {
- this.destination.complete();
+ this.destination.complete!();
}
this.unsubscribe();
}
- notifyNext(outerValue: T, innerValue: R,
- outerIndex: number, innerIndex: number,
- innerSub: InnerSubscriber<T, R>): void {
+ notifyNext(innerValue: R): void {
this._next(innerValue);
}
- notifyComplete(innerSub: Subscription): void {
+ notifyComplete(): void {
const buffer = this.buffer;
- const destination = this.destination as Subscription;
- destination.remove(innerSub);
this.active--;
if (buffer && buffer.length > 0) {
this._next(buffer.shift());
}
if (this.hasCompleted && this.active === 0) {
- this.destination.complete();
+ this.destination.complete!();
}
}
}