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

types(config): add GlobalConfig interface #6247

Merged
merged 6 commits into from Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions api_guard/dist/types/index.d.ts
Expand Up @@ -69,13 +69,7 @@ export interface CompletionObserver<T> {
export declare function concat<T extends readonly unknown[]>(...inputs: [...ObservableInputTuple<T>]): Observable<T[number]>;
export declare function concat<T extends readonly unknown[]>(...inputsAndScheduler: [...ObservableInputTuple<T>, SchedulerLike]): Observable<T[number]>;

export declare const config: {
onUnhandledError: ((err: any) => void) | null;
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
Promise: PromiseConstructorLike | undefined;
useDeprecatedSynchronousErrorHandling: boolean;
useDeprecatedNextContext: boolean;
};
export declare const config: GlobalConfig;

export declare function connectable<T>(source: ObservableInput<T>, connector?: Subject<T>): ConnectableObservableLike<T>;

Expand Down Expand Up @@ -162,6 +156,14 @@ export declare function generate<S>(initialState: S, condition: ConditionFunc<S>
export declare function generate<S>(options: GenerateBaseOptions<S>): Observable<S>;
export declare function generate<T, S>(options: GenerateOptions<T, S>): Observable<T>;

export interface GlobalConfig {
Promise: PromiseConstructorLike | undefined;
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
onUnhandledError: ((err: any) => void) | null;
useDeprecatedNextContext: boolean;
useDeprecatedSynchronousErrorHandling: boolean;
}

export interface GroupedObservable<K, T> extends Observable<T> {
readonly key: K;
}
Expand Down
61 changes: 4 additions & 57 deletions src/internal/config.ts
@@ -1,71 +1,18 @@
import { Subscriber } from './Subscriber';
import { ObservableNotification } from './types';
import { ObservableNotification, GlobalConfig } from './types';

/**
* The global configuration object for RxJS, used to configure things
* like what Promise constructor should used to create Promises
* The {@link GlobalConfig} object for RxJS. It is used to configure things
* like how to react on unhandled errors.
*/
export const config = {
/**
* A registration point for unhandled errors from RxJS. These are errors that
* cannot were not handled by consuming code in the usual subscription path. For
* example, if you have this configured, and you subscribe to an observable without
* providing an error handler, errors from that subscription will end up here. This
* will _always_ be called asynchronously on another job in the runtime. This is because
* we do not want errors thrown in this user-configured handler to interfere with the
* behavior of the library.
*/
export const config: GlobalConfig = {
onUnhandledError: null as ((err: any) => void) | null,

/**
* A registration point for notifications that cannot be sent to subscribers because they
* have completed, errored or have been explicitly unsubscribed. By default, next, complete
* and error notifications sent to stopped subscribers are noops. However, sometimes callers
* might want a different behavior. For example, with sources that attempt to report errors
* to stopped subscribers, a caller can configure RxJS to throw an unhandled error instead.
* This will _always_ be called asynchronously on another job in the runtime. This is because
* we do not want errors thrown in this user-configured handler to interfere with the
* behavior of the library.
*/
onStoppedNotification: null as ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null,

/**
* The promise constructor used by default for methods such as
* {@link toPromise} and {@link forEach}
*
* @deprecated remove in v8. 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 Promises as you see appropriate.
*/
Promise: undefined as PromiseConstructorLike | undefined,

/**
* 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
* call in a try/catch block. It also enables producer interference, a nasty bug
* where a multicast can be broken for all observers by a downstream consumer with
* an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BUY TIME
* FOR MIGRATION REASONS.
*
* @deprecated remove in v8. As of version 8, RxJS will no longer support synchronous throwing
* of unhandled errors. All errors will be thrown on a separate call stack to prevent bad
* behaviors described above.
*/
useDeprecatedSynchronousErrorHandling: false,

/**
* If true, enables an as-of-yet undocumented feature from v5: The ability to access
* `unsubscribe()` via `this` context in `next` functions created in observers passed
* to `subscribe`.
*
* This is being removed because the performance was severely problematic, and it could also cause
* issues when types other than POJOs are passed to subscribe as subscribers, as they will likely have
* their `this` context overwritten.
*
* @deprecated remove in v8. As of version 8, RxJS will no longer support altering the
* context of next functions provided as part of an observer to Subscribe. Instead,
* you will have access to a subscription or a signal or token that will allow you to do things like
* unsubscribe and test closed status.
*/
useDeprecatedNextContext: false,
};
71 changes: 71 additions & 0 deletions src/internal/types.ts
Expand Up @@ -3,6 +3,7 @@

import { Observable } from './Observable';
import { Subscription } from './Subscription';
import { Subscriber } from './Subscriber';

/**
* Note: This will add Symbol.observable globally for all TypeScript users,
Expand Down Expand Up @@ -302,3 +303,73 @@ interface ReadableStreamDefaultReaderLike<T> {
export interface ReadableStreamLike<T> {
getReader(): ReadableStreamDefaultReaderLike<T>;
}

/**
* The global configuration object for RxJS, used to configure things
* like how to react on unhandled errors. Accessible via {@link config}
* object.
*/
export interface GlobalConfig {
cartant marked this conversation as resolved.
Show resolved Hide resolved
/**
* A registration point for unhandled errors from RxJS. These are errors that
* cannot were not handled by consuming code in the usual subscription path. For
* example, if you have this configured, and you subscribe to an observable without
* providing an error handler, errors from that subscription will end up here. This
* will _always_ be called asynchronously on another job in the runtime. This is because
* we do not want errors thrown in this user-configured handler to interfere with the
* behavior of the library.
*/
onUnhandledError: ((err: any) => void) | null;

/**
* A registration point for notifications that cannot be sent to subscribers because they
* have completed, errored or have been explicitly unsubscribed. By default, next, complete
* and error notifications sent to stopped subscribers are noops. However, sometimes callers
* might want a different behavior. For example, with sources that attempt to report errors
* to stopped subscribers, a caller can configure RxJS to throw an unhandled error instead.
* This will _always_ be called asynchronously on another job in the runtime. This is because
* we do not want errors thrown in this user-configured handler to interfere with the
* behavior of the library.
*/
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;

/**
* The promise constructor used by default for methods such as
* {@link Observable/toPromise} and {@link Observable/forEach}
*
* @deprecated remove in v8. 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 Promises as you see appropriate.
*/
Promise: PromiseConstructorLike | undefined;

/**
* 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
* call in a try/catch block. It also enables producer interference, a nasty bug
* where a multicast can be broken for all observers by a downstream consumer with
* an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BUY TIME
* FOR MIGRATION REASONS.
*
* @deprecated remove in v8. As of version 8, RxJS will no longer support synchronous throwing
* of unhandled errors. All errors will be thrown on a separate call stack to prevent bad
* behaviors described above.
*/
useDeprecatedSynchronousErrorHandling: boolean;

/**
* If true, enables an as-of-yet undocumented feature from v5: The ability to access
* `unsubscribe()` via `this` context in `next` functions created in observers passed
* to `subscribe`.
*
* This is being removed because the performance was severely problematic, and it could also cause
* issues when types other than POJOs are passed to subscribe as subscribers, as they will likely have
* their `this` context overwritten.
*
* @deprecated remove in v8. As of version 8, RxJS will no longer support altering the
* context of next functions provided as part of an observer to Subscribe. Instead,
* you will have access to a subscription or a signal or token that will allow you to do things like
* unsubscribe and test closed status.
*/
useDeprecatedNextContext: boolean;
}