Home Reference Source Test

dist/reactive.js

import { Subject } from 'rxjs/Subject';
import { ObjectUnsubscribedError } from 'rxjs/util/ObjectUnsubscribedError';
/**
 * MemorizingSubject acts like a BehaviorSubject, except that it is seeded
 * with no value, calls to getValue() will fail before the first `next` call,
 * and it does not push a value to subscribers if `next` has not been called.
 */
export class MemorizingSubject extends Subject {
    constructor() {
        super(...arguments);
        this.hasSet = false;
    }
    hasValue() {
        return this.hasSet;
    }
    forget() {
        this.hasSet = false;
    }
    next(value) {
        this.hasSet = true;
        super.next((this.value = value));
    }
    getValue() {
        if (this.hasError) {
            throw this.thrownError;
        }
        if (this.closed) {
            throw new ObjectUnsubscribedError();
        }
        if (!this.hasSet) {
            throw new Error('Attempted to call `getValue` on a MemorizingSubject' +
                'which did not previous have its value set.');
        }
        return this.value;
    }
    // tslint:disable-next-line
    _subscribe(subscriber) {
        const subscription = super._subscribe(subscriber);
        if (subscription && this.hasSet && !subscription.closed) {
            subscriber.next(this.value);
        }
        return subscription;
    }
}