Skip to content

Commit

Permalink
types(config): add GlobalConfig interface (#6247)
Browse files Browse the repository at this point in the history
* chore(config): add GlobalConfig interface

* chore: update api_guardian

* chore: move GlobalConfig declaration to config.ts

* chore: update api_guardian

* chore: remove excessive types from config properties

* chore(config): remove extra empty lines
  • Loading branch information
jakovljevic-mladen committed Apr 29, 2021
1 parent 839e192 commit 02a9098
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
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>, config?: ConnectableConfig<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;
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
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -98,4 +98,4 @@ export { NEVER } from './internal/observable/never';
export * from './internal/types';

/* Config */
export { config } from './internal/config';
export { config, GlobalConfig } from './internal/config';
33 changes: 23 additions & 10 deletions src/internal/config.ts
@@ -1,11 +1,24 @@
import { Subscriber } from './Subscriber';
import { ObservableNotification } from './types';

/**
* The {@link GlobalConfig} object for RxJS. It is used to configure things
* like how to react on unhandled errors.
*/
export const config: GlobalConfig = {
onUnhandledError: null,
onStoppedNotification: null,
Promise: undefined,
useDeprecatedSynchronousErrorHandling: false,
useDeprecatedNextContext: false,
};

/**
* The global configuration object for RxJS, used to configure things
* like what Promise constructor should used to create Promises
* like how to react on unhandled errors. Accessible via {@link config}
* object.
*/
export const config = {
export interface GlobalConfig {
/**
* 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
Expand All @@ -15,7 +28,7 @@ export const config = {
* we do not want errors thrown in this user-configured handler to interfere with the
* behavior of the library.
*/
onUnhandledError: null as ((err: any) => void) | null,
onUnhandledError: ((err: any) => void) | null;

/**
* A registration point for notifications that cannot be sent to subscribers because they
Expand All @@ -27,17 +40,17 @@ export const config = {
* 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,
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;

/**
* The promise constructor used by default for methods such as
* {@link toPromise} and {@link forEach}
* The promise constructor used by default for {@link toPromise} and {@link 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: undefined as PromiseConstructorLike | undefined,
Promise?: PromiseConstructorLike;

/**
* If true, turns on synchronous error rethrowing, which is a deprecated behavior
Expand All @@ -51,7 +64,7 @@ export const config = {
* of unhandled errors. All errors will be thrown on a separate call stack to prevent bad
* behaviors described above. Will be removed in v8.
*/
useDeprecatedSynchronousErrorHandling: false,
useDeprecatedSynchronousErrorHandling: boolean;

/**
* If true, enables an as-of-yet undocumented feature from v5: The ability to access
Expand All @@ -67,5 +80,5 @@ export const config = {
* 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. Will be removed in v8.
*/
useDeprecatedNextContext: false,
};
useDeprecatedNextContext: boolean;
}

0 comments on commit 02a9098

Please sign in to comment.