import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; /** * @return {Observable|WebSocketSubject|Observable} * @method toArray * @owner Observable */ export function toArray(this: Observable): Observable { return this.lift(new ToArrayOperator()); } class ToArrayOperator implements Operator { call(subscriber: Subscriber, source: any): any { return source.subscribe(new ToArraySubscriber(subscriber)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class ToArraySubscriber extends Subscriber { private array: T[] = []; constructor(destination: Subscriber) { super(destination); } protected _next(x: T) { this.array.push(x); } protected _complete() { this.destination.next(this.array); this.destination.complete(); } }