diff --git a/src/ReplaySubject.ts b/src/ReplaySubject.ts index 0ab64ee603..71655aed01 100644 --- a/src/ReplaySubject.ts +++ b/src/ReplaySubject.ts @@ -41,7 +41,7 @@ export class ReplaySubject extends Subject { } else if (this.isStopped) { subscription = Subscription.EMPTY; } else { - this.observers.push(subscriber); + this._observers.push(subscriber); subscription = new SubjectSubscription(this, subscriber); } diff --git a/src/Subject.ts b/src/Subject.ts index b3dacf0d80..ba223ceca1 100644 --- a/src/Subject.ts +++ b/src/Subject.ts @@ -25,15 +25,23 @@ export class Subject extends Observable implements ISubscription { return new SubjectSubscriber(this); } - observers: Observer[] = []; - - closed = false; + protected _observers: Array> = []; + public get observers(): ReadonlyArray> { + return this._observers; + } - isStopped = false; + protected _closed: boolean = false; + public get closed(): boolean { + return this._closed; + } - hasError = false; + protected _isStopped: boolean = false; + public get isStopped(): boolean { + return this._isStopped; + } - thrownError: any = null; + protected hasError: boolean = false; + protected thrownError: any = null; constructor() { super(); @@ -69,34 +77,34 @@ export class Subject extends Observable implements ISubscription { } this.hasError = true; this.thrownError = err; - this.isStopped = true; + this._isStopped = true; const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].error(err); } - this.observers.length = 0; + this._observers.length = 0; } complete() { if (this.closed) { throw new ObjectUnsubscribedError(); } - this.isStopped = true; + this._isStopped = true; const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].complete(); } - this.observers.length = 0; + this._observers.length = 0; } unsubscribe() { - this.isStopped = true; - this.closed = true; - this.observers = null; + this._isStopped = true; + this._closed = true; + this._observers = null; } protected _subscribe(subscriber: Subscriber): Subscription { @@ -109,7 +117,7 @@ export class Subject extends Observable implements ISubscription { subscriber.complete(); return Subscription.EMPTY; } else { - this.observers.push(subscriber); + this._observers.push(subscriber); return new SubjectSubscription(this, subscriber); } } diff --git a/src/SubjectSubscription.ts b/src/SubjectSubscription.ts index c7080ed6f5..8ca2e5fa68 100644 --- a/src/SubjectSubscription.ts +++ b/src/SubjectSubscription.ts @@ -22,7 +22,7 @@ export class SubjectSubscription extends Subscription { this.closed = true; const subject = this.subject; - const observers = subject.observers; + const observers = (subject as any)._observers; this.subject = null;