Code coverage report for src/subject/BehaviorSubject.ts

Statements: 100% (31 / 31)      Branches: 87.5% (7 / 8)      Functions: 100% (7 / 7)      Lines: 100% (28 / 28)      Ignored: none     

All files » src/subject/ » BehaviorSubject.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 471     1 1   1 30     30 30     1 8 1 7 1   6       1 3     1 58 58 19 39 39   39     1 71     1 4 4   1
import {Subject} from '../Subject';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {throwError} from '../util/throwError';
import {ObjectUnsubscribedError} from '../util/ObjectUnsubscribedError';
 
export class BehaviorSubject<T> extends Subject<T> {
  private _hasError: boolean = false;
  private _err: any;
 
  constructor(private _value: T) {
    super();
  }
 
  getValue(): T {
    if (this._hasError) {
      throwError(this._err);
    } else if (this.isUnsubscribed) {
      throwError(new ObjectUnsubscribedError());
    } else {
      return this._value;
    }
  }
 
  get value(): T {
    return this.getValue();
  }
 
  _subscribe(subscriber: Subscriber<any>): Subscription<T> {
    const subscription = super._subscribe(subscriber);
    if (!subscription) {
      return;
    } else Eif (!subscription.isUnsubscribed) {
      subscriber.next(this._value);
    }
    return subscription;
  }
 
  _next(value: T): void {
    super._next(this._value = value);
  }
 
  _error(err: any): void {
    this._hasError = true;
    super._error(this._err = err);
  }
}