From 6446b66f6edbf454efde6d633b3655522af514b5 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 10 Apr 2018 13:45:01 -0700 Subject: [PATCH] fix(node/TS): eliminate incompatable types to protected properties Resolves an issue in Node and TypeScript where if a project had more than one copy of RxJS, even if it was the same version, types would be incompatable between say, Observable and Observable, due to protected fields in the dts files. As all of these fields are really implementation details of the library, and my be removed at any time do to architectural changes, it is prudent to mark them as deprecated. Marking them as public only serves to eliminate the type incompatibilities. --- src/internal/AsyncSubject.ts | 3 ++- src/internal/BehaviorSubject.ts | 3 ++- src/internal/Observable.ts | 13 ++++++++----- src/internal/ReplaySubject.ts | 3 ++- src/internal/Subject.ts | 9 ++++++--- src/internal/Subscriber.ts | 6 ++++-- src/internal/observable/ConnectableObservable.ts | 5 +++-- src/internal/observable/SubscribeOnObservable.ts | 3 ++- src/internal/observable/dom/AjaxObservable.ts | 3 ++- src/internal/observable/dom/WebSocketSubject.ts | 6 ++++-- src/internal/operators/bufferTime.ts | 3 ++- src/internal/operators/bufferWhen.ts | 3 ++- src/internal/operators/delayWhen.ts | 5 +++-- src/internal/operators/groupBy.ts | 6 ++++-- src/internal/operators/repeatWhen.ts | 6 ++++-- src/internal/operators/retryWhen.ts | 3 ++- src/internal/operators/timeoutWith.ts | 3 ++- src/internal/operators/window.ts | 3 ++- src/internal/operators/windowToggle.ts | 3 ++- src/internal/scheduler/AsyncAction.ts | 3 ++- src/internal/testing/HotObservable.ts | 3 ++- 21 files changed, 62 insertions(+), 33 deletions(-) diff --git a/src/internal/AsyncSubject.ts b/src/internal/AsyncSubject.ts index 49e97caa67..09d4a54006 100644 --- a/src/internal/AsyncSubject.ts +++ b/src/internal/AsyncSubject.ts @@ -10,7 +10,8 @@ export class AsyncSubject extends Subject { private hasNext: boolean = false; private hasCompleted: boolean = false; - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { if (this.hasError) { subscriber.error(this.thrownError); return Subscription.EMPTY; diff --git a/src/internal/BehaviorSubject.ts b/src/internal/BehaviorSubject.ts index a91407088e..3a11d264b3 100644 --- a/src/internal/BehaviorSubject.ts +++ b/src/internal/BehaviorSubject.ts @@ -17,7 +17,8 @@ export class BehaviorSubject extends Subject { return this.getValue(); } - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { const subscription = super._subscribe(subscriber); if (subscription && !(subscription).closed) { subscriber.next(this._value); diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index 1620e8bf03..237e2bbfe7 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -21,9 +21,11 @@ export class Observable implements Subscribable { /** Internal implementation detail, do not use directly. */ public _isScalar: boolean = false; - protected source: Observable; + /** @deprecated This is an internal implementation detail, do not use. */ + source: Observable; - protected operator: Operator; + /** @deprecated This is an internal implementation detail, do not use. */ + operator: Operator; /** * @constructor @@ -208,7 +210,8 @@ export class Observable implements Subscribable { return sink; } - protected _trySubscribe(sink: Subscriber): TeardownLogic { + /** @deprecated This is an internal implementation detail, do not use. */ + _trySubscribe(sink: Subscriber): TeardownLogic { try { return this._subscribe(sink); } catch (err) { @@ -247,8 +250,8 @@ export class Observable implements Subscribable { }) as Promise; } - /** @internal */ - protected _subscribe(subscriber: Subscriber): TeardownLogic { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): TeardownLogic { const { source } = this; return source && source.subscribe(subscriber); } diff --git a/src/internal/ReplaySubject.ts b/src/internal/ReplaySubject.ts index 171cc48581..5f4fc0928f 100644 --- a/src/internal/ReplaySubject.ts +++ b/src/internal/ReplaySubject.ts @@ -49,7 +49,8 @@ export class ReplaySubject extends Subject { super.next(value); } - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { // When `_infiniteTimeWindow === true` then the buffer is already trimmed const _infiniteTimeWindow = this._infiniteTimeWindow; const _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents(); diff --git a/src/internal/Subject.ts b/src/internal/Subject.ts index bbb39eaa6c..4ce87298b3 100644 --- a/src/internal/Subject.ts +++ b/src/internal/Subject.ts @@ -100,7 +100,8 @@ export class Subject extends Observable implements SubscriptionLike { this.observers = null; } - protected _trySubscribe(subscriber: Subscriber): TeardownLogic { + /** @deprecated This is an internal implementation detail, do not use. */ + _trySubscribe(subscriber: Subscriber): TeardownLogic { if (this.closed) { throw new ObjectUnsubscribedError(); } else { @@ -108,7 +109,8 @@ export class Subject extends Observable implements SubscriptionLike { } } - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { if (this.closed) { throw new ObjectUnsubscribedError(); } else if (this.hasError) { @@ -160,7 +162,8 @@ export class AnonymousSubject extends Subject { } } - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { const { source } = this; if (source) { return this.source.subscribe(subscriber); diff --git a/src/internal/Subscriber.ts b/src/internal/Subscriber.ts index 35d60b3d38..f7ad950a49 100644 --- a/src/internal/Subscriber.ts +++ b/src/internal/Subscriber.ts @@ -152,7 +152,8 @@ export class Subscriber extends Subscription implements Observer { this.unsubscribe(); } - protected _unsubscribeAndRecycle(): Subscriber { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribeAndRecycle(): Subscriber { const { _parent, _parents } = this; this._parent = null; this._parents = null; @@ -296,7 +297,8 @@ class SafeSubscriber extends Subscriber { return false; } - protected _unsubscribe(): void { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe(): void { const { _parentSubscriber } = this; this._context = null; this._parentSubscriber = null; diff --git a/src/internal/observable/ConnectableObservable.ts b/src/internal/observable/ConnectableObservable.ts index e3e887eea6..44d6fd9998 100644 --- a/src/internal/observable/ConnectableObservable.ts +++ b/src/internal/observable/ConnectableObservable.ts @@ -17,12 +17,13 @@ export class ConnectableObservable extends Observable { /** @internal */ _isComplete = false; - constructor(protected source: Observable, + constructor(public source: Observable, protected subjectFactory: () => Subject) { super(); } - protected _subscribe(subscriber: Subscriber) { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber) { return this.getSubject().subscribe(subscriber); } diff --git a/src/internal/observable/SubscribeOnObservable.ts b/src/internal/observable/SubscribeOnObservable.ts index 64839cf63c..d66e3b100d 100644 --- a/src/internal/observable/SubscribeOnObservable.ts +++ b/src/internal/observable/SubscribeOnObservable.ts @@ -39,7 +39,8 @@ export class SubscribeOnObservable extends Observable { } } - protected _subscribe(subscriber: Subscriber) { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber) { const delay = this.delayTime; const source = this.source; const scheduler = this.scheduler; diff --git a/src/internal/observable/dom/AjaxObservable.ts b/src/internal/observable/dom/AjaxObservable.ts index 51de1dcbc2..d708d39c69 100644 --- a/src/internal/observable/dom/AjaxObservable.ts +++ b/src/internal/observable/dom/AjaxObservable.ts @@ -179,7 +179,8 @@ export class AjaxObservable extends Observable { this.request = request; } - protected _subscribe(subscriber: Subscriber): TeardownLogic { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): TeardownLogic { return new AjaxSubscriber(subscriber, this.request); } } diff --git a/src/internal/observable/dom/WebSocketSubject.ts b/src/internal/observable/dom/WebSocketSubject.ts index 76a015dd17..ee68790e17 100644 --- a/src/internal/observable/dom/WebSocketSubject.ts +++ b/src/internal/observable/dom/WebSocketSubject.ts @@ -68,7 +68,8 @@ export class WebSocketSubject extends AnonymousSubject { private _config: WebSocketSubjectConfig; - protected _output: Subject; + /** @deprecated This is an internal implementation detail, do not use. */ + _output: Subject; private _socket: WebSocket; @@ -263,7 +264,8 @@ export class WebSocketSubject extends AnonymousSubject { }; } - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { const { source } = this; if (source) { return source.subscribe(subscriber); diff --git a/src/internal/operators/bufferTime.ts b/src/internal/operators/bufferTime.ts index ceed50ea0d..11f9205cc3 100644 --- a/src/internal/operators/bufferTime.ts +++ b/src/internal/operators/bufferTime.ts @@ -170,7 +170,8 @@ class BufferTimeSubscriber extends Subscriber { super._complete(); } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { this.contexts = null; } diff --git a/src/internal/operators/bufferWhen.ts b/src/internal/operators/bufferWhen.ts index 96a69d0c7c..5dc40404af 100644 --- a/src/internal/operators/bufferWhen.ts +++ b/src/internal/operators/bufferWhen.ts @@ -85,7 +85,8 @@ class BufferWhenSubscriber extends OuterSubscriber { super._complete(); } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { this.buffer = null; this.subscribing = false; } diff --git a/src/internal/operators/delayWhen.ts b/src/internal/operators/delayWhen.ts index 730d7cb9cf..f2c0d4a702 100644 --- a/src/internal/operators/delayWhen.ts +++ b/src/internal/operators/delayWhen.ts @@ -161,11 +161,12 @@ class DelayWhenSubscriber extends OuterSubscriber { * @extends {Ignored} */ class SubscriptionDelayObservable extends Observable { - constructor(protected source: Observable, private subscriptionDelay: Observable) { + constructor(public source: Observable, private subscriptionDelay: Observable) { super(); } - protected _subscribe(subscriber: Subscriber) { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber) { this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source)); } } diff --git a/src/internal/operators/groupBy.ts b/src/internal/operators/groupBy.ts index fd6ab94f90..cf2e0fb7c5 100644 --- a/src/internal/operators/groupBy.ts +++ b/src/internal/operators/groupBy.ts @@ -234,7 +234,8 @@ class GroupDurationSubscriber extends Subscriber { this.complete(); } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { const { parent, key } = this; this.key = this.parent = null; if (parent) { @@ -258,7 +259,8 @@ export class GroupedObservable extends Observable { super(); } - protected _subscribe(subscriber: Subscriber) { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber) { const subscription = new Subscription(); const { refCountSubscription, groupSubject } = this; if (refCountSubscription && !refCountSubscription.closed) { diff --git a/src/internal/operators/repeatWhen.ts b/src/internal/operators/repeatWhen.ts index 1af2e86f59..8bfe3e4b1d 100644 --- a/src/internal/operators/repeatWhen.ts +++ b/src/internal/operators/repeatWhen.ts @@ -86,7 +86,8 @@ class RepeatWhenSubscriber extends OuterSubscriber { } } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { const { notifications, retriesSubscription } = this; if (notifications) { notifications.unsubscribe(); @@ -99,7 +100,8 @@ class RepeatWhenSubscriber extends OuterSubscriber { this.retries = null; } - protected _unsubscribeAndRecycle(): Subscriber { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribeAndRecycle(): Subscriber { const { _unsubscribe } = this; this._unsubscribe = null; diff --git a/src/internal/operators/retryWhen.ts b/src/internal/operators/retryWhen.ts index 616c618bbf..ec4c402e5e 100644 --- a/src/internal/operators/retryWhen.ts +++ b/src/internal/operators/retryWhen.ts @@ -86,7 +86,8 @@ class RetryWhenSubscriber extends OuterSubscriber { } } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { const { errors, retriesSubscription } = this; if (errors) { errors.unsubscribe(); diff --git a/src/internal/operators/timeoutWith.ts b/src/internal/operators/timeoutWith.ts index 85104dcb7a..75458c80a1 100644 --- a/src/internal/operators/timeoutWith.ts +++ b/src/internal/operators/timeoutWith.ts @@ -129,7 +129,8 @@ class TimeoutWithSubscriber extends OuterSubscriber { super._next(value); } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { this.action = null; this.scheduler = null; this.withObservable = null; diff --git a/src/internal/operators/window.ts b/src/internal/operators/window.ts index 9da0851085..d0dba99435 100644 --- a/src/internal/operators/window.ts +++ b/src/internal/operators/window.ts @@ -106,7 +106,8 @@ class WindowSubscriber extends OuterSubscriber { this.destination.complete(); } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { this.window = null; } diff --git a/src/internal/operators/windowToggle.ts b/src/internal/operators/windowToggle.ts index c3543c479e..4a6a36b205 100644 --- a/src/internal/operators/windowToggle.ts +++ b/src/internal/operators/windowToggle.ts @@ -134,7 +134,8 @@ class WindowToggleSubscriber extends OuterSubscriber { super._complete(); } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { const { contexts } = this; this.contexts = null; if (contexts) { diff --git a/src/internal/scheduler/AsyncAction.ts b/src/internal/scheduler/AsyncAction.ts index c898cdbedb..d61502e3e8 100644 --- a/src/internal/scheduler/AsyncAction.ts +++ b/src/internal/scheduler/AsyncAction.ts @@ -129,7 +129,8 @@ export class AsyncAction extends Action { } } - protected _unsubscribe() { + /** @deprecated This is an internal implementation detail, do not use. */ + _unsubscribe() { const id = this.id; const scheduler = this.scheduler; diff --git a/src/internal/testing/HotObservable.ts b/src/internal/testing/HotObservable.ts index 8918890ab9..28a94a4e95 100644 --- a/src/internal/testing/HotObservable.ts +++ b/src/internal/testing/HotObservable.ts @@ -24,7 +24,8 @@ export class HotObservable extends Subject implements SubscriptionLoggable this.scheduler = scheduler; } - protected _subscribe(subscriber: Subscriber): Subscription { + /** @deprecated This is an internal implementation detail, do not use. */ + _subscribe(subscriber: Subscriber): Subscription { const subject: HotObservable = this; const index = subject.logSubscribedFrame(); subscriber.add(new Subscription(() => {