Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removed config.Promise injection point. #6597

Merged
merged 2 commits into from Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion api_guard/dist/types/index.d.ts
Expand Up @@ -275,7 +275,6 @@ export declare function generate<S>(options: GenerateBaseOptions<S>): Observable
export declare function generate<T, S>(options: GenerateOptions<T, S>): Observable<T>;

export interface GlobalConfig {
Promise?: PromiseConstructorLike;
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
onUnhandledError: ((err: any) => void) | null;
useDeprecatedNextContext: boolean;
Expand Down
19 changes: 0 additions & 19 deletions spec/Observable-spec.ts
Expand Up @@ -86,25 +86,6 @@ describe('Observable', () => {
);
});

it('should allow Promise to be globally configured', async () => {
try {
let wasCalled = false;

config.Promise = function MyPromise(callback: any) {
wasCalled = true;
return new Promise<number>(callback);
} as any;

await of(42).forEach((x) => {
expect(x).to.equal(42);
})

expect(wasCalled).to.be.true;
} finally {
config.Promise = undefined;
}
});

it('should reject promise if nextHandler throws', (done) => {
const results: number[] = [];

Expand Down
5 changes: 0 additions & 5 deletions spec/config-spec.ts
Expand Up @@ -6,11 +6,6 @@ import { Observable } from 'rxjs';
import { timeoutProvider } from 'rxjs/internal/scheduler/timeoutProvider';

describe('config', () => {
it('should have a Promise property that defaults to nothing', () => {
expect(config).to.have.property('Promise');
expect(config.Promise).to.be.undefined;
});

describe('onUnhandledError', () => {
afterEach(() => {
config.onUnhandledError = null;
Expand Down
16 changes: 0 additions & 16 deletions spec/operators/toPromise-spec.ts
Expand Up @@ -33,20 +33,4 @@ describe('Observable.toPromise', () => {
}
);
});

it('should allow for global config via config.Promise', async () => {
try {
let wasCalled = false;
config.Promise = function MyPromise(callback: Function) {
wasCalled = true;
return new Promise(callback as any);
} as any;

const x = await of(42).toPromise();
expect(wasCalled).to.be.true;
expect(x).to.equal(42);
} finally {
config.Promise = undefined;
}
});
});
3 changes: 1 addition & 2 deletions src/internal/Observable.ts
Expand Up @@ -7,7 +7,6 @@ import { isSubscription, Subscription } from './Subscription';
import { TeardownLogic, OperatorFunction, Subscribable, Observer } from './types';
import { observable as Symbol_observable } from './symbol/observable';
import { pipeFromArray } from './util/pipe';
import { config } from './config';
import { isFunction } from './util/isFunction';
import { errorContext } from './util/errorContext';

Expand Down Expand Up @@ -488,7 +487,7 @@ export class Observable<T> implements Subscribable<T> {
* @param promiseCtor The optional promise constructor to passed by consuming code
*/
function getPromiseCtor(promiseCtor: PromiseConstructorLike | undefined) {
return promiseCtor ?? config.Promise ?? Promise;
return promiseCtor ?? Promise;
}

function isObserver<T>(value: any): value is Observer<T> {
Expand Down
11 changes: 0 additions & 11 deletions src/internal/config.ts
Expand Up @@ -8,7 +8,6 @@ import { ObservableNotification } from './types';
export const config: GlobalConfig = {
onUnhandledError: null,
onStoppedNotification: null,
Promise: undefined,
useDeprecatedSynchronousErrorHandling: false,
useDeprecatedNextContext: false,
};
Expand Down Expand Up @@ -42,16 +41,6 @@ export interface GlobalConfig {
*/
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;

/**
* The promise constructor used by default for {@link Observable#toPromise toPromise} and {@link Observable#forEach forEach}
* methods.
*
* @deprecated As of version 8, RxJS will no longer support this sort of injection of a
* Promise constructor. If you need a Promise implementation other than native promises,
* please polyfill/patch Promise as you see appropriate. Will be removed in v8.
*/
Promise?: PromiseConstructorLike;

/**
* If true, turns on synchronous error rethrowing, which is a deprecated behavior
* in v6 and higher. This behavior enables bad patterns like wrapping a subscribe
Expand Down