1 import { Subject } from './Subject';
2 import { Subscriber } from './Subscriber';
3 import { Subscription } from './Subscription';
4 import { SubscriptionLike } from './types';
5 import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';
8 * A variant of Subject that requires an initial value and emits its current
9 * value whenever it is subscribed to.
11 * @class BehaviorSubject<T>
13 export class BehaviorSubject<T> extends Subject<T> {
15 constructor(private _value: T) {
20 return this.getValue();
23 /** @deprecated This is an internal implementation detail, do not use. */
24 _subscribe(subscriber: Subscriber<T>): Subscription {
25 const subscription = super._subscribe(subscriber);
26 if (subscription && !(<SubscriptionLike>subscription).closed) {
27 subscriber.next(this._value);
34 throw this.thrownError;
35 } else if (this.closed) {
36 throw new ObjectUnsubscribedError();
42 next(value: T): void {
43 super.next(this._value = value);