Code coverage report for src/operator/toArray.ts

Statements: 100% (19 / 19)      Branches: 100% (0 / 0)      Functions: 100% (7 / 7)      Lines: 100% (17 / 17)      Ignored: none     

All files » src/operator/ » toArray.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  1     1 10     2 1 10   1   1   10   1 10     1 10     1 4 4   1  
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
 
export function toArray<T>(): Observable<T[]> {
  return this.lift(new ToArrayOperator());
}
 
class ToArrayOperator<T> implements Operator<T, T[]> {
  call(subscriber: Subscriber<T[]>): Subscriber<T> {
    return new ToArraySubscriber(subscriber);
  }
}
 
class ToArraySubscriber<T> extends Subscriber<T> {
 
  private array: T[] = [];
 
  constructor(destination: Subscriber<T[]>) {
    super(destination);
  }
 
  protected _next(x: T) {
    this.array.push(x);
  }
 
  protected _complete() {
    this.destination.next(this.array);
    this.destination.complete();
  }
}