Code coverage report for src/subject/AsyncSubject.ts

Statements: 100% (31 / 31)      Branches: 100% (6 / 6)      Functions: 100% (5 / 5)      Lines: 100% (29 / 29)      Ignored: none     

All files » src/subject/ » AsyncSubject.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 511       1 33 33 33   1 33     1 57 4     57     1 52 52     1 20 20 20     20 20   20 17 18 18 18     3 3       20   1  
import {Subject} from '../Subject';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
 
export class AsyncSubject<T> extends Subject<T> {
  _value: T = void 0;
  _hasNext: boolean = false;
  _isScalar: boolean = false;
 
  constructor () {
    super();
  }
 
  _subscribe(subscriber: Subscriber<any>): Subscription<T> {
    if (this.completeSignal && this._hasNext) {
      subscriber.next(this._value);
    }
 
    return super._subscribe(subscriber);
  }
 
  _next(value: T): void {
    this._value = value;
    this._hasNext = true;
  }
 
  _complete(): void {
    let index = -1;
    const observers = this.observers;
    const len = observers.length;
 
    // optimization -- block next, complete, and unsubscribe while dispatching
    this.observers = void 0; // optimization
    this.isUnsubscribed = true;
 
    if (this._hasNext) {
      while (++index < len) {
        let o = observers[index];
        o.next(this._value);
        o.complete();
      }
    } else {
      while (++index < len) {
        observers[index].complete();
      }
    }
 
    this.isUnsubscribed = false;
  }
}