From 69f5bfae0eb2880a3d5cfb34db3a182182b325de Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Wed, 28 Jul 2021 14:55:44 -0500 Subject: [PATCH] fix: Expose `Connectable`, return type of `connectable` (#6531) Resolves #6529 --- api_guard/dist/types/index.d.ts | 6 +++++- src/internal/observable/connectable.ts | 18 ++---------------- src/internal/types.ts | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/api_guard/dist/types/index.d.ts b/api_guard/dist/types/index.d.ts index 0a8d005684..41afe32eb5 100644 --- a/api_guard/dist/types/index.d.ts +++ b/api_guard/dist/types/index.d.ts @@ -112,7 +112,11 @@ export declare const config: GlobalConfig; export declare function connect>(selector: (shared: Observable) => O, config?: ConnectConfig): OperatorFunction>; -export declare function connectable(source: ObservableInput, config?: ConnectableConfig): ConnectableObservableLike; +export declare function connectable(source: ObservableInput, config?: ConnectableConfig): Connectable; + +export interface Connectable extends Observable { + connect(): Subscription; +} export declare class ConnectableObservable extends Observable { protected _connection: Subscription | null; diff --git a/src/internal/observable/connectable.ts b/src/internal/observable/connectable.ts index 635dcc72b8..4a840ee795 100644 --- a/src/internal/observable/connectable.ts +++ b/src/internal/observable/connectable.ts @@ -1,23 +1,9 @@ -import { ObservableInput, SubjectLike } from '../types'; +import { Connectable, ObservableInput, SubjectLike } from '../types'; import { Subject } from '../Subject'; import { Subscription } from '../Subscription'; import { Observable } from '../Observable'; import { defer } from './defer'; -/** - * An observable with a `connect` method that is used to create a subscription - * to an underlying source, connecting it with all consumers via a multicast. - */ -export interface ConnectableObservableLike extends Observable { - /** - * (Idempotent) Calling this method will connect the underlying source observable to all subscribed consumers - * through an underlying {@link Subject}. - * @returns A subscription, that when unsubscribed, will "disconnect" the source from the connector subject, - * severing notifications to all consumers. - */ - connect(): Subscription; -} - export interface ConnectableConfig { /** * A factory function used to create the Subject through which the source @@ -51,7 +37,7 @@ const DEFAULT_CONFIG: ConnectableConfig = { * @returns A "connectable" observable, that has a `connect()` method, that you must call to * connect the source to all consumers through the subject provided as the connector. */ -export function connectable(source: ObservableInput, config: ConnectableConfig = DEFAULT_CONFIG): ConnectableObservableLike { +export function connectable(source: ObservableInput, config: ConnectableConfig = DEFAULT_CONFIG): Connectable { // The subscription representing the connection. let connection: Subscription | null = null; const { connector, resetOnDisconnect = true } = config; diff --git a/src/internal/types.ts b/src/internal/types.ts index c0ba9637ed..62516dd341 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -308,3 +308,17 @@ interface ReadableStreamDefaultReaderLike { export interface ReadableStreamLike { getReader(): ReadableStreamDefaultReaderLike; } + +/** + * An observable with a `connect` method that is used to create a subscription + * to an underlying source, connecting it with all consumers via a multicast. + */ +export interface Connectable extends Observable { + /** + * (Idempotent) Calling this method will connect the underlying source observable to all subscribed consumers + * through an underlying {@link Subject}. + * @returns A subscription, that when unsubscribed, will "disconnect" the source from the connector subject, + * severing notifications to all consumers. + */ + connect(): Subscription; +}