Code coverage report for src/operator/window.ts

Statements: 100% (45 / 45)      Branches: 50% (1 / 2)      Functions: 100% (15 / 15)      Lines: 100% (39 / 39)      Ignored: none     

All files » src/operator/ » window.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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69  1   1   1 12     1   12     1 12   1   1 12   12 12 12 12     1 36     1 3 3     1 7 7     1 28 28 28   28   1   1 12 12     1 16     1 1     1 3   1  
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {Subject} from '../Subject';
 
export function window<T>(closingNotifier: Observable<any>): Observable<Observable<T>> {
  return this.lift(new WindowOperator(closingNotifier));
}
 
class WindowOperator<T, R> implements Operator<T, R> {
 
  constructor(private closingNotifier: Observable<any>) {
  }
 
  call(subscriber: Subscriber<T>): Subscriber<T> {
    return new WindowSubscriber(subscriber, this.closingNotifier);
  }
}
 
class WindowSubscriber<T> extends Subscriber<T> {
  private window: Subject<T> = new Subject<T>();
 
  constructor(destination: Subscriber<T>, private closingNotifier: Observable<any>) {
    super(destination);
    this.add(closingNotifier._subscribe(new WindowClosingNotifierSubscriber(this)));
    this.openWindow();
  }
 
  _next(value: T) {
    this.window.next(value);
  }
 
  _error(err: any) {
    this.window.error(err);
    this.destination.error(err);
  }
 
  _complete() {
    this.window.complete();
    this.destination.complete();
  }
 
  openWindow() {
    const prevWindow = this.window;
    Eif (prevWindow) {
      prevWindow.complete();
    }
    this.destination.next(this.window = new Subject<T>());
  }
}
 
class WindowClosingNotifierSubscriber<T> extends Subscriber<T> {
  constructor(private parent: WindowSubscriber<any>) {
    super(null);
  }
 
  _next() {
    this.parent.openWindow();
  }
 
  _error(err: any) {
    this.parent._error(err);
  }
 
  _complete() {
    this.parent._complete();
  }
}