diff --git a/api_guard/dist/types/index.d.ts b/api_guard/dist/types/index.d.ts index 41baf154ca..4ba5c9268e 100644 --- a/api_guard/dist/types/index.d.ts +++ b/api_guard/dist/types/index.d.ts @@ -21,7 +21,6 @@ export declare const async: AsyncScheduler; export declare const asyncScheduler: AsyncScheduler; export declare class AsyncSubject extends Subject { - protected _checkFinalizedStatuses(subscriber: Subscriber): void; complete(): void; next(value: T): void; } @@ -29,7 +28,6 @@ export declare class AsyncSubject extends Subject { export declare class BehaviorSubject extends Subject { get value(): T; constructor(_value: T); - protected _subscribe(subscriber: Subscriber): Subscription; getValue(): T; next(value: T): void; } @@ -88,7 +86,6 @@ export declare class ConnectableObservable extends Observable { source: Observable; protected subjectFactory: () => Subject; constructor(source: Observable, subjectFactory: () => Subject); - protected _subscribe(subscriber: Subscriber): Subscription; protected _teardown(): void; connect(): Subscription; protected getSubject(): Subject; @@ -253,14 +250,12 @@ export declare const ObjectUnsubscribedError: ObjectUnsubscribedErrorCtor; export declare const observable: string | symbol; export declare class Observable implements Subscribable { - protected operator: Operator | undefined; - protected source: Observable | undefined; + operator: Operator | undefined; + source: Observable | undefined; constructor(subscribe?: (this: Observable, subscriber: Subscriber) => TeardownLogic); - protected _subscribe(subscriber: Subscriber): TeardownLogic; - protected _trySubscribe(sink: Subscriber): TeardownLogic; forEach(next: (value: T) => void): Promise; forEach(next: (value: T) => void, promiseCtor: PromiseConstructorLike): Promise; - protected lift(operator?: Operator): Observable; + lift(operator?: Operator): Observable; pipe(): Observable; pipe(op1: OperatorFunction): Observable; pipe(op1: OperatorFunction, op2: OperatorFunction): Observable; @@ -365,8 +360,7 @@ export interface ReadableStreamLike { } export declare class ReplaySubject extends Subject { - constructor(bufferSize?: number, windowTime?: number, timestampProvider?: TimestampProvider); - protected _subscribe(subscriber: Subscriber): Subscription; + constructor(_bufferSize?: number, _windowTime?: number, _timestampProvider?: TimestampProvider); next(value: T): void; } @@ -399,11 +393,6 @@ export declare class Subject extends Observable implements SubscriptionLik observers: Observer[]; thrownError: any; constructor(); - protected _checkFinalizedStatuses(subscriber: Subscriber): void; - protected _innerSubscribe(subscriber: Subscriber): Subscription; - protected _subscribe(subscriber: Subscriber): Subscription; - protected _throwIfClosed(): void; - protected _trySubscribe(subscriber: Subscriber): TeardownLogic; asObservable(): Observable; complete(): void; error(err: any): void; diff --git a/api_guard/dist/types/webSocket/index.d.ts b/api_guard/dist/types/webSocket/index.d.ts index 42264cb80b..737704275f 100644 --- a/api_guard/dist/types/webSocket/index.d.ts +++ b/api_guard/dist/types/webSocket/index.d.ts @@ -1,9 +1,7 @@ export declare function webSocket(urlConfigOrSource: string | WebSocketSubjectConfig): WebSocketSubject; export declare class WebSocketSubject extends AnonymousSubject { - _output: Subject; constructor(urlConfigOrSource: string | WebSocketSubjectConfig | Observable, destination?: Observer); - _subscribe(subscriber: Subscriber): Subscription; lift(operator: Operator): WebSocketSubject; multiplex(subMsg: () => any, unsubMsg: () => any, messageFilter: (value: T) => boolean): Observable; unsubscribe(): void; diff --git a/docs_app/src/app/custom-elements/toc/toc.component.spec.ts b/docs_app/src/app/custom-elements/toc/toc.component.spec.ts index dba9118445..473f608ad5 100644 --- a/docs_app/src/app/custom-elements/toc/toc.component.spec.ts +++ b/docs_app/src/app/custom-elements/toc/toc.component.spec.ts @@ -467,7 +467,7 @@ class TestTocService { activeItemIndex = new BehaviorSubject(null); setActiveIndex(index: number|null) { this.activeItemIndex.next(index); - if (asap.scheduled !== undefined) { + if (asap._scheduled !== undefined) { asap.flush(); } } diff --git a/package.json b/package.json index 816f214cfd..1b5ec0e720 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "test:side-effects": "check-side-effects --test integration/side-effects/side-effects.json", "test:side-effects:update": "npm run test:side-effects -- --update", "test:import": "ts-node ./integration/import/runner.ts", - "compile": "tsc -b ./src/tsconfig.cjs.json ./src/tsconfig.cjs.spec.json ./src/tsconfig.esm.json ./src/tsconfig.esm5.json ./src/tsconfig.esm5.rollup.json ./src/tsconfig.types.json ./spec/tsconfig.json", + "compile": "tsc -b ./src/tsconfig.cjs.json ./src/tsconfig.cjs.spec.json ./src/tsconfig.esm.json ./src/tsconfig.esm5.json ./src/tsconfig.esm5.rollup.json ./src/tsconfig.types.json ./src/tsconfig.types.spec.json ./spec/tsconfig.json", "build:clean": "shx rm -rf ./dist", "build:global": "node ./tools/make-umd-bundle.js && node ./tools/make-closure-core.js", "build:package": "npm-run-all build:clean compile build:global && node ./tools/prepare-package.js && node ./tools/generate-alias.js", diff --git a/spec/Scheduler-spec.ts b/spec/Scheduler-spec.ts index 8b32314dc3..69d3a05b65 100644 --- a/spec/Scheduler-spec.ts +++ b/spec/Scheduler-spec.ts @@ -7,7 +7,7 @@ describe('Scheduler.queue', () => { it('should schedule things recursively', () => { let call1 = false; let call2 = false; - (queue as QueueScheduler).active = false; + (queue as QueueScheduler)._active = false; queue.schedule(() => { call1 = true; queue.schedule(() => { @@ -21,7 +21,7 @@ describe('Scheduler.queue', () => { it('should schedule things recursively via this.schedule', () => { let call1 = false; let call2 = false; - (queue as QueueScheduler).active = false; + (queue as QueueScheduler)._active = false; queue.schedule(function (state) { call1 = state!.call1; call2 = state!.call2; diff --git a/spec/observables/interval-spec.ts b/spec/observables/interval-spec.ts index 7a209920c0..e398554ccf 100644 --- a/spec/observables/interval-spec.ts +++ b/spec/observables/interval-spec.ts @@ -77,7 +77,7 @@ describe('interval', () => { }, complete() { expect(asapScheduler.actions.length).to.equal(0); - expect(asapScheduler.scheduled).to.equal(undefined); + expect(asapScheduler._scheduled).to.equal(undefined); sandbox.restore(); done(); } @@ -104,7 +104,7 @@ describe('interval', () => { }, complete() { expect(queueScheduler.actions.length).to.equal(0); - expect(queueScheduler.scheduled).to.equal(undefined); + expect(queueScheduler._scheduled).to.equal(undefined); sandbox.restore(); done(); } @@ -131,7 +131,7 @@ describe('interval', () => { }, complete() { expect(animationFrameScheduler.actions.length).to.equal(0); - expect(animationFrameScheduler.scheduled).to.equal(undefined); + expect(animationFrameScheduler._scheduled).to.equal(undefined); sandbox.restore(); done(); } diff --git a/spec/schedulers/AnimationFrameScheduler-spec.ts b/spec/schedulers/AnimationFrameScheduler-spec.ts index 57a0d0f88f..faa8e81ada 100644 --- a/spec/schedulers/AnimationFrameScheduler-spec.ts +++ b/spec/schedulers/AnimationFrameScheduler-spec.ts @@ -103,12 +103,12 @@ describe('Scheduler.animationFrame', () => { let animationFrameExec2 = false; const action1 = animationFrame.schedule(() => { animationFrameExec1 = true; }); const action2 = animationFrame.schedule(() => { animationFrameExec2 = true; }); - expect(animationFrame.scheduled).to.exist; + expect(animationFrame._scheduled).to.exist; expect(animationFrame.actions.length).to.equal(2); action1.unsubscribe(); action2.unsubscribe(); expect(animationFrame.actions.length).to.equal(0); - expect(animationFrame.scheduled).to.equal(undefined); + expect(animationFrame._scheduled).to.equal(undefined); animationFrame.schedule(() => { expect(animationFrameExec1).to.equal(false); expect(animationFrameExec2).to.equal(false); diff --git a/spec/schedulers/AsapScheduler-spec.ts b/spec/schedulers/AsapScheduler-spec.ts index 22a3ced199..f70ea29bf4 100644 --- a/spec/schedulers/AsapScheduler-spec.ts +++ b/spec/schedulers/AsapScheduler-spec.ts @@ -156,12 +156,12 @@ describe('Scheduler.asap', () => { let asapExec2 = false; const action1 = asap.schedule(() => { asapExec1 = true; }); const action2 = asap.schedule(() => { asapExec2 = true; }); - expect(asap.scheduled).to.exist; + expect(asap._scheduled).to.exist; expect(asap.actions.length).to.equal(2); action1.unsubscribe(); action2.unsubscribe(); expect(asap.actions.length).to.equal(0); - expect(asap.scheduled).to.equal(undefined); + expect(asap._scheduled).to.equal(undefined); asap.schedule(() => { expect(asapExec1).to.equal(false); expect(asapExec2).to.equal(false); diff --git a/spec/tsconfig.json b/spec/tsconfig.json index a88aa3614f..316120d15c 100644 --- a/spec/tsconfig.json +++ b/spec/tsconfig.json @@ -9,7 +9,7 @@ }, "references": [ { - "path": "../src/tsconfig.types.json" + "path": "../src/tsconfig.types.spec.json" } ] } \ No newline at end of file diff --git a/src/internal/AnyCatcher.ts b/src/internal/AnyCatcher.ts index b42ff7a7b8..e69ebe1fca 100644 --- a/src/internal/AnyCatcher.ts +++ b/src/internal/AnyCatcher.ts @@ -1,10 +1,14 @@ +/* + * Note that we cannot apply the `internal` tag here because the declaration + * needs to survive the `stripInternal` option. Otherwise, `AnyCatcher` will + * be `any` in the `.d.ts` files. + */ +declare const anyCatcherSymbol: unique symbol; + /** * This is just a type that we're using to identify `any` being passed to * function overloads. This is used because of situations like {@link forkJoin}, * where it could return an `Observable` or an `Observable<{ [key: K]: T }>`, * so `forkJoin(any)` would mean we need to return `Observable`. - * - * @internal */ -declare const anyCatcherSymbol: unique symbol; export type AnyCatcher = typeof anyCatcherSymbol; diff --git a/src/internal/AsyncSubject.ts b/src/internal/AsyncSubject.ts index ea80cc4a96..0b4027aea4 100644 --- a/src/internal/AsyncSubject.ts +++ b/src/internal/AsyncSubject.ts @@ -8,32 +8,33 @@ import { Subscriber } from './Subscriber'; * @class AsyncSubject */ export class AsyncSubject extends Subject { - private value: T | null = null; - private hasValue = false; - private isComplete = false; + private _value: T | null = null; + private _hasValue = false; + private _isComplete = false; + /** @internal */ protected _checkFinalizedStatuses(subscriber: Subscriber) { - const { hasError, hasValue, value, thrownError, isStopped } = this; + const { hasError, _hasValue, _value, thrownError, isStopped } = this; if (hasError) { subscriber.error(thrownError); } else if (isStopped) { - hasValue && subscriber.next(value!); + _hasValue && subscriber.next(_value!); subscriber.complete(); } } next(value: T): void { if (!this.isStopped) { - this.value = value; - this.hasValue = true; + this._value = value; + this._hasValue = true; } } complete(): void { - const { hasValue, value, isComplete } = this; - if (!isComplete) { - this.isComplete = true; - hasValue && super.next(value!); + const { _hasValue, _value, _isComplete } = this; + if (!_isComplete) { + this._isComplete = true; + _hasValue && super.next(_value!); super.complete(); } } diff --git a/src/internal/BehaviorSubject.ts b/src/internal/BehaviorSubject.ts index bc0b32882c..8e561797a8 100644 --- a/src/internal/BehaviorSubject.ts +++ b/src/internal/BehaviorSubject.ts @@ -17,7 +17,7 @@ export class BehaviorSubject extends Subject { return this.getValue(); } - /** @deprecated This is an internal implementation detail, do not use. */ + /** @internal */ protected _subscribe(subscriber: Subscriber): Subscription { const subscription = super._subscribe(subscriber); !subscription.closed && subscriber.next(this._value); diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index 8ec18d83f0..1e5d027274 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -17,11 +17,15 @@ import { isFunction } from './util/isFunction'; * @class Observable */ export class Observable implements Subscribable { - /** @deprecated This is an internal implementation detail, do not use. */ - protected source: Observable | undefined; + /** + * @deprecated This is an internal implementation detail, do not use. + */ + source: Observable | undefined; - /** @deprecated This is an internal implementation detail, do not use. */ - protected operator: Operator | undefined; + /** + * @deprecated This is an internal implementation detail, do not use. + */ + operator: Operator | undefined; /** * @constructor @@ -61,7 +65,7 @@ export class Observable implements Subscribable { * using `lift`, it is recommended that you create an operator by simply returning `new Observable()` directly. * See "Creating new operators from scratch" section here: https://rxjs.dev/guide/operators */ - protected lift(operator?: Operator): Observable { + lift(operator?: Operator): Observable { const observable = new Observable(); observable.source = this; observable.operator = operator; @@ -250,7 +254,7 @@ export class Observable implements Subscribable { return subscriber; } - /** @deprecated This is an internal implementation detail, do not use. */ + /** @internal */ protected _trySubscribe(sink: Subscriber): TeardownLogic { try { return this._subscribe(sink); @@ -343,7 +347,7 @@ export class Observable implements Subscribable { }) as Promise; } - /** @internal This is an internal implementation detail, do not use. */ + /** @internal */ protected _subscribe(subscriber: Subscriber): TeardownLogic { return this.source?.subscribe(subscriber); } diff --git a/src/internal/ReplaySubject.ts b/src/internal/ReplaySubject.ts index 8e721bc1bf..85f5c71d60 100644 --- a/src/internal/ReplaySubject.ts +++ b/src/internal/ReplaySubject.ts @@ -35,8 +35,8 @@ import { dateTimestampProvider } from './scheduler/dateTimestampProvider'; * @see {@link shareReplay} */ export class ReplaySubject extends Subject { - private buffer: (T | number)[] = []; - private infiniteTimeWindow = true; + private _buffer: (T | number)[] = []; + private _infiniteTimeWindow = true; /** * @param bufferSize The size of the buffer to replay on subscription @@ -45,38 +45,38 @@ export class ReplaySubject extends Subject { * calculate the amount of time something has been buffered. */ constructor( - private bufferSize = Infinity, - private windowTime = Infinity, - private timestampProvider: TimestampProvider = dateTimestampProvider + private _bufferSize = Infinity, + private _windowTime = Infinity, + private _timestampProvider: TimestampProvider = dateTimestampProvider ) { super(); - this.infiniteTimeWindow = windowTime === Infinity; - this.bufferSize = Math.max(1, bufferSize); - this.windowTime = Math.max(1, windowTime); + this._infiniteTimeWindow = _windowTime === Infinity; + this._bufferSize = Math.max(1, _bufferSize); + this._windowTime = Math.max(1, _windowTime); } next(value: T): void { - const { isStopped, buffer, infiniteTimeWindow, timestampProvider, windowTime } = this; + const { isStopped, _buffer, _infiniteTimeWindow, _timestampProvider, _windowTime } = this; if (!isStopped) { - buffer.push(value); - !infiniteTimeWindow && buffer.push(timestampProvider.now() + windowTime); + _buffer.push(value); + !_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime); } - this.trimBuffer(); + this._trimBuffer(); super.next(value); } - /** @deprecated Remove in v8. This is an internal implementation detail, do not use. */ + /** @internal */ protected _subscribe(subscriber: Subscriber): Subscription { this._throwIfClosed(); - this.trimBuffer(); + this._trimBuffer(); const subscription = this._innerSubscribe(subscriber); - const { infiniteTimeWindow, buffer } = this; + const { _infiniteTimeWindow, _buffer } = this; // We use a copy here, so reentrant code does not mutate our array while we're // emitting it to a new subscriber. - const copy = buffer.slice(); - for (let i = 0; i < copy.length && !subscriber.closed; i += infiniteTimeWindow ? 1 : 2) { + const copy = _buffer.slice(); + for (let i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) { subscriber.next(copy[i] as T); } @@ -85,26 +85,26 @@ export class ReplaySubject extends Subject { return subscription; } - private trimBuffer() { - const { bufferSize, timestampProvider, buffer, infiniteTimeWindow } = this; + private _trimBuffer() { + const { _bufferSize, _timestampProvider, _buffer, _infiniteTimeWindow } = this; // If we don't have an infinite buffer size, and we're over the length, // use splice to truncate the old buffer values off. Note that we have to // double the size for instances where we're not using an infinite time window // because we're storing the values and the timestamps in the same array. - const adjustedBufferSize = (infiniteTimeWindow ? 1 : 2) * bufferSize; - bufferSize < Infinity && adjustedBufferSize < buffer.length && buffer.splice(0, buffer.length - adjustedBufferSize); + const adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize; + _bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize); // Now, if we're not in an infinite time window, remove all values where the time is // older than what is allowed. - if (!infiniteTimeWindow) { - const now = timestampProvider.now(); + if (!_infiniteTimeWindow) { + const now = _timestampProvider.now(); let last = 0; // Search the array for the first timestamp that isn't expired and // truncate the buffer up to that point. - for (let i = 1; i < buffer.length && (buffer[i] as number) <= now; i += 2) { + for (let i = 1; i < _buffer.length && (_buffer[i] as number) <= now; i += 2) { last = i; } - last && buffer.splice(0, last + 1); + last && _buffer.splice(0, last + 1); } } } diff --git a/src/internal/Subject.ts b/src/internal/Subject.ts index c932f0c6b5..1edb3ca52b 100644 --- a/src/internal/Subject.ts +++ b/src/internal/Subject.ts @@ -14,14 +14,14 @@ import { arrRemove } from './util/arrRemove'; * Subject, and you can call next to feed values as well as error and complete. */ export class Subject extends Observable implements SubscriptionLike { - observers: Observer[] = []; - closed = false; - + /** @deprecated This is an internal implementation detail, do not use directly. */ + observers: Observer[] = []; + /** @deprecated This is an internal implementation detail, do not use directly. */ isStopped = false; - + /** @deprecated This is an internal implementation detail, do not use directly. */ hasError = false; - + /** @deprecated This is an internal implementation detail, do not use directly. */ thrownError: any = null; /** @@ -39,12 +39,14 @@ export class Subject extends Observable implements SubscriptionLike { super(); } + /** @deprecated This is an internal implementation detail, do not use directly. */ lift(operator: Operator): Observable { const subject = new AnonymousSubject(this, this); subject.operator = operator as any; return subject as any; } + /** @internal */ protected _throwIfClosed() { if (this.closed) { throw new ObjectUnsubscribedError(); @@ -89,26 +91,28 @@ export class Subject extends Observable implements SubscriptionLike { this.observers = null!; } - /** @deprecated This is an internal implementation detail, do not use. */ + /** @internal */ protected _trySubscribe(subscriber: Subscriber): TeardownLogic { this._throwIfClosed(); return super._trySubscribe(subscriber); } - /** @deprecated This is an internal implementation detail, do not use. */ + /** @internal */ protected _subscribe(subscriber: Subscriber): Subscription { this._throwIfClosed(); this._checkFinalizedStatuses(subscriber); return this._innerSubscribe(subscriber); } + /** @internal */ protected _innerSubscribe(subscriber: Subscriber) { const { hasError, isStopped, observers } = this; return hasError || isStopped ? EMPTY_SUBSCRIPTION - : (observers.push(subscriber), new Subscription(() => arrRemove(this.observers, subscriber))); + : (observers.push(subscriber), new Subscription(() => arrRemove(observers, subscriber))); } + /** @internal */ protected _checkFinalizedStatuses(subscriber: Subscriber) { const { hasError, thrownError, isStopped } = this; if (hasError) { @@ -117,6 +121,7 @@ export class Subject extends Observable implements SubscriptionLike { subscriber.complete(); } } + /** * Creates a new Observable with this Subject as the source. You can do this * to create customize Observer-side logic of the Subject and conceal it from @@ -134,7 +139,11 @@ export class Subject extends Observable implements SubscriptionLike { * @class AnonymousSubject */ export class AnonymousSubject extends Subject { - constructor(protected destination?: Observer, source?: Observable) { + constructor( + /** @deprecated Internal implementation detail, do not use. */ + public destination?: Observer, + source?: Observable + ) { super(); this.source = source; } @@ -151,8 +160,8 @@ export class AnonymousSubject extends Subject { this.destination?.complete?.(); } - /** @deprecated This is an internal implementation detail, do not use. */ - _subscribe(subscriber: Subscriber): Subscription { + /** @internal */ + protected _subscribe(subscriber: Subscriber): Subscription { return this.source?.subscribe(subscriber) ?? EMPTY_SUBSCRIPTION; } } diff --git a/src/internal/Subscriber.ts b/src/internal/Subscriber.ts index 29b1942eb6..e88179609d 100644 --- a/src/internal/Subscriber.ts +++ b/src/internal/Subscriber.ts @@ -35,7 +35,9 @@ export class Subscriber extends Subscription implements Observer { return new SafeSubscriber(next, error, complete); } + /** @deprecated This is an internal implementation detail, do not use directly. */ protected isStopped: boolean = false; + /** @deprecated This is an internal implementation detail, do not use directly. */ protected destination: Subscriber | Observer; // this `any` is the escape hatch to erase extra type param (e.g. R) /** diff --git a/src/internal/observable/ConnectableObservable.ts b/src/internal/observable/ConnectableObservable.ts index fa85142bf8..03e3844501 100644 --- a/src/internal/observable/ConnectableObservable.ts +++ b/src/internal/observable/ConnectableObservable.ts @@ -37,6 +37,7 @@ export class ConnectableObservable extends Observable { } } + /** @internal */ protected _subscribe(subscriber: Subscriber) { return this.getSubject().subscribe(subscriber); } diff --git a/src/internal/observable/dom/WebSocketSubject.ts b/src/internal/observable/dom/WebSocketSubject.ts index 534cf1d675..4dbef942b9 100644 --- a/src/internal/observable/dom/WebSocketSubject.ts +++ b/src/internal/observable/dom/WebSocketSubject.ts @@ -134,7 +134,7 @@ export interface WebSocketSubjectConfig { * WebSocket impl in Node (WebSocket is a DOM API), or for mocking a WebSocket * for testing purposes */ - WebSocketCtor?: { new(url: string, protocols?: string|string[]): WebSocket }; + WebSocketCtor?: { new (url: string, protocols?: string | string[]): WebSocket }; /** Sets the `binaryType` property of the underlying WebSocket. */ binaryType?: 'blob' | 'arraybuffer'; } @@ -151,11 +151,10 @@ const WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT = export type WebSocketMessage = string | ArrayBuffer | Blob | ArrayBufferView; export class WebSocketSubject extends AnonymousSubject { - // @ts-ignore: Property has no initializer and is not definitely assigned private _config: WebSocketSubjectConfig; - /** @deprecated This is an internal implementation detail, do not use. */ + /** @internal */ // @ts-ignore: Property has no initializer and is not definitely assigned _output: Subject; @@ -167,7 +166,7 @@ export class WebSocketSubject extends AnonymousSubject { this.destination = destination; this.source = urlConfigOrSource as Observable; } else { - const config = this._config = { ...DEFAULT_WEBSOCKET_CONFIG }; + const config = (this._config = { ...DEFAULT_WEBSOCKET_CONFIG }); this._output = new Subject(); if (typeof urlConfigOrSource === 'string') { config.url = urlConfigOrSource; @@ -230,17 +229,19 @@ export class WebSocketSubject extends AnonymousSubject { observer.error(err); } - const subscription = self.subscribe(x => { - try { - if (messageFilter(x)) { - observer.next(x); + const subscription = self.subscribe( + (x) => { + try { + if (messageFilter(x)) { + observer.next(x); + } + } catch (err) { + observer.error(err); } - } catch (err) { - observer.error(err); - } - }, - err => observer.error(err), - () => observer.complete()); + }, + (err) => observer.error(err), + () => observer.complete() + ); return () => { try { @@ -259,9 +260,7 @@ export class WebSocketSubject extends AnonymousSubject { let socket: WebSocket | null = null; try { - socket = protocol ? - new WebSocketCtor!(url, protocol) : - new WebSocketCtor!(url); + socket = protocol ? new WebSocketCtor!(url, protocol) : new WebSocketCtor!(url); this._socket = socket; if (binaryType) { this._socket.binaryType = binaryType; @@ -298,7 +297,7 @@ export class WebSocketSubject extends AnonymousSubject { try { const { serializer } = this._config; socket!.send(serializer!(x!)); - } catch (e) { + } catch (e) { this.destination!.error(e); } } @@ -358,8 +357,8 @@ export class WebSocketSubject extends AnonymousSubject { }; } - /** @deprecated This is an internal implementation detail, do not use. */ - _subscribe(subscriber: Subscriber): Subscription { + /** @internal */ + protected _subscribe(subscriber: Subscriber): Subscription { const { source } = this; if (source) { return source.subscribe(subscriber); diff --git a/src/internal/scheduler/AnimationFrameAction.ts b/src/internal/scheduler/AnimationFrameAction.ts index ef5e2a5b6b..1ab54d82f6 100644 --- a/src/internal/scheduler/AnimationFrameAction.ts +++ b/src/internal/scheduler/AnimationFrameAction.ts @@ -4,9 +4,7 @@ import { SchedulerAction } from '../types'; import { animationFrameProvider } from './animationFrameProvider'; export class AnimationFrameAction extends AsyncAction { - - constructor(protected scheduler: AnimationFrameScheduler, - protected work: (this: SchedulerAction, state?: T) => void) { + constructor(protected scheduler: AnimationFrameScheduler, protected work: (this: SchedulerAction, state?: T) => void) { super(scheduler, work); } @@ -20,8 +18,7 @@ export class AnimationFrameAction extends AsyncAction { // If an animation frame has already been requested, don't request another // one. If an animation frame hasn't been requested yet, request one. Return // the current animation frame request id. - return scheduler.scheduled || (scheduler.scheduled = animationFrameProvider.requestAnimationFrame( - () => scheduler.flush(undefined))); + return scheduler._scheduled || (scheduler._scheduled = animationFrameProvider.requestAnimationFrame(() => scheduler.flush(undefined))); } protected recycleAsyncId(scheduler: AnimationFrameScheduler, id?: any, delay: number = 0): any { // If delay exists and is greater than 0, or if the delay is null (the @@ -35,7 +32,7 @@ export class AnimationFrameAction extends AsyncAction { // request its own. if (scheduler.actions.length === 0) { animationFrameProvider.cancelAnimationFrame(id); - scheduler.scheduled = undefined; + scheduler._scheduled = undefined; } // Return undefined so the action knows to request a new async id if it's rescheduled. return undefined; diff --git a/src/internal/scheduler/AnimationFrameScheduler.ts b/src/internal/scheduler/AnimationFrameScheduler.ts index dd0593c650..888b603553 100644 --- a/src/internal/scheduler/AnimationFrameScheduler.ts +++ b/src/internal/scheduler/AnimationFrameScheduler.ts @@ -3,23 +3,22 @@ import { AsyncScheduler } from './AsyncScheduler'; export class AnimationFrameScheduler extends AsyncScheduler { public flush(action?: AsyncAction): void { + this._active = true; + this._scheduled = undefined; - this.active = true; - this.scheduled = undefined; - - const {actions} = this; + const { actions } = this; let error: any; let index = -1; action = action || actions.shift()!; const count = actions.length; do { - if (error = action.execute(action.state, action.delay)) { + if ((error = action.execute(action.state, action.delay))) { break; } } while (++index < count && (action = actions.shift())); - this.active = false; + this._active = false; if (error) { while (++index < count && (action = actions.shift())) { diff --git a/src/internal/scheduler/AsapAction.ts b/src/internal/scheduler/AsapAction.ts index 87ad7fd258..a9239b0d56 100644 --- a/src/internal/scheduler/AsapAction.ts +++ b/src/internal/scheduler/AsapAction.ts @@ -4,9 +4,7 @@ import { SchedulerAction } from '../types'; import { immediateProvider } from './immediateProvider'; export class AsapAction extends AsyncAction { - - constructor(protected scheduler: AsapScheduler, - protected work: (this: SchedulerAction, state?: T) => void) { + constructor(protected scheduler: AsapScheduler, protected work: (this: SchedulerAction, state?: T) => void) { super(scheduler, work); } @@ -20,9 +18,7 @@ export class AsapAction extends AsyncAction { // If a microtask has already been scheduled, don't schedule another // one. If a microtask hasn't been scheduled yet, schedule one now. Return // the current scheduled microtask id. - return scheduler.scheduled || (scheduler.scheduled = immediateProvider.setImmediate( - scheduler.flush.bind(scheduler, undefined) - )); + return scheduler._scheduled || (scheduler._scheduled = immediateProvider.setImmediate(scheduler.flush.bind(scheduler, undefined))); } protected recycleAsyncId(scheduler: AsapScheduler, id?: any, delay: number = 0): any { // If delay exists and is greater than 0, or if the delay is null (the @@ -36,7 +32,7 @@ export class AsapAction extends AsyncAction { // its own. if (scheduler.actions.length === 0) { immediateProvider.clearImmediate(id); - scheduler.scheduled = undefined; + scheduler._scheduled = undefined; } // Return undefined so the action knows to request a new async id if it's rescheduled. return undefined; diff --git a/src/internal/scheduler/AsapScheduler.ts b/src/internal/scheduler/AsapScheduler.ts index 2b65483c7e..55408bc4ea 100644 --- a/src/internal/scheduler/AsapScheduler.ts +++ b/src/internal/scheduler/AsapScheduler.ts @@ -3,23 +3,22 @@ import { AsyncScheduler } from './AsyncScheduler'; export class AsapScheduler extends AsyncScheduler { public flush(action?: AsyncAction): void { + this._active = true; + this._scheduled = undefined; - this.active = true; - this.scheduled = undefined; - - const {actions} = this; + const { actions } = this; let error: any; let index = -1; action = action || actions.shift()!; const count = actions.length; do { - if (error = action.execute(action.state, action.delay)) { + if ((error = action.execute(action.state, action.delay))) { break; } } while (++index < count && (action = actions.shift())); - this.active = false; + this._active = false; if (error) { while (++index < count && (action = actions.shift())) { diff --git a/src/internal/scheduler/AsyncScheduler.ts b/src/internal/scheduler/AsyncScheduler.ts index 27912644a4..518ab24b21 100644 --- a/src/internal/scheduler/AsyncScheduler.ts +++ b/src/internal/scheduler/AsyncScheduler.ts @@ -8,44 +8,43 @@ export class AsyncScheduler extends Scheduler { * A flag to indicate whether the Scheduler is currently executing a batch of * queued actions. * @type {boolean} - * @deprecated internal use only + * @internal */ - public active: boolean = false; + public _active: boolean = false; /** * An internal ID used to track the latest asynchronous task such as those * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and * others. * @type {any} - * @deprecated internal use only + * @internal */ - public scheduled: any = undefined; + public _scheduled: any = undefined; constructor(SchedulerAction: typeof Action, now: () => number = Scheduler.now) { super(SchedulerAction, now); } public flush(action: AsyncAction): void { + const { actions } = this; - const {actions} = this; - - if (this.active) { + if (this._active) { actions.push(action); return; } let error: any; - this.active = true; + this._active = true; do { - if (error = action.execute(action.state, action.delay)) { + if ((error = action.execute(action.state, action.delay))) { break; } - } while (action = actions.shift()!); // exhaust the scheduler queue + } while ((action = actions.shift()!)); // exhaust the scheduler queue - this.active = false; + this._active = false; if (error) { - while (action = actions.shift()!) { + while ((action = actions.shift()!)) { action.unsubscribe(); } throw error; diff --git a/src/internal/testing/HotObservable.ts b/src/internal/testing/HotObservable.ts index 7f57b041b4..c151480620 100644 --- a/src/internal/testing/HotObservable.ts +++ b/src/internal/testing/HotObservable.ts @@ -21,8 +21,8 @@ export class HotObservable extends Subject implements SubscriptionLoggable this.scheduler = scheduler; } - /** @deprecated This is an internal implementation detail, do not use. */ - _subscribe(subscriber: Subscriber): Subscription { + /** @internal */ + protected _subscribe(subscriber: Subscriber): Subscription { const subject: HotObservable = this; const index = subject.logSubscribedFrame(); const subscription = new Subscription(); diff --git a/src/tsconfig.types.spec.json b/src/tsconfig.types.spec.json new file mode 100644 index 0000000000..7766b1fc2d --- /dev/null +++ b/src/tsconfig.types.spec.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.types.json", + "compilerOptions": { + "declarationDir": "../dist/types_spec", + "stripInternal": false + } +} diff --git a/tsconfig.json b/tsconfig.json index c7735ef8b5..cf9451b733 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "strict": true, "noImplicitReturns": true, "moduleResolution": "node", - "stripInternal": false, + "stripInternal": true, "noEmit": true, "lib": [ "esnext",