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

fix: Expose Connectable, return type of connectable #6531

Merged
merged 1 commit into from Jul 28, 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
6 changes: 5 additions & 1 deletion api_guard/dist/types/index.d.ts
Expand Up @@ -112,7 +112,11 @@ export declare const config: GlobalConfig;

export declare function connect<T, O extends ObservableInput<unknown>>(selector: (shared: Observable<T>) => O, config?: ConnectConfig<T>): OperatorFunction<T, ObservedValueOf<O>>;

export declare function connectable<T>(source: ObservableInput<T>, config?: ConnectableConfig<T>): ConnectableObservableLike<T>;
export declare function connectable<T>(source: ObservableInput<T>, config?: ConnectableConfig<T>): Connectable<T>;

export interface Connectable<T> extends Observable<T> {
connect(): Subscription;
}

export declare class ConnectableObservable<T> extends Observable<T> {
protected _connection: Subscription | null;
Expand Down
18 changes: 2 additions & 16 deletions 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<T> extends Observable<T> {
/**
* (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<T> {
/**
* A factory function used to create the Subject through which the source
Expand Down Expand Up @@ -51,7 +37,7 @@ const DEFAULT_CONFIG: ConnectableConfig<unknown> = {
* @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<T>(source: ObservableInput<T>, config: ConnectableConfig<T> = DEFAULT_CONFIG): ConnectableObservableLike<T> {
export function connectable<T>(source: ObservableInput<T>, config: ConnectableConfig<T> = DEFAULT_CONFIG): Connectable<T> {
// The subscription representing the connection.
let connection: Subscription | null = null;
const { connector, resetOnDisconnect = true } = config;
Expand Down
14 changes: 14 additions & 0 deletions src/internal/types.ts
Expand Up @@ -308,3 +308,17 @@ interface ReadableStreamDefaultReaderLike<T> {
export interface ReadableStreamLike<T> {
getReader(): ReadableStreamDefaultReaderLike<T>;
}

/**
* 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<T> extends Observable<T> {
/**
* (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;
}