Skip to content

Commit

Permalink
refactor: Removing AnonymousSubject lift remnants
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Nov 22, 2023
1 parent d62ce6e commit 5d0c71d
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions packages/rxjs/src/internal/observable/dom/WebSocketSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,38 +154,32 @@ export type WebSocketMessage = string | ArrayBuffer | Blob | ArrayBufferView;
export class WebSocketSubject<T> extends Subject<T> {
private _config!: WebSocketSubjectConfig<T>;

/** @internal */
_output!: Subject<T>;
private _output: Subject<T>;

private _socket: WebSocket | null = null;

private destination: Observer<T> | undefined = undefined;
private destination: Observer<T>;

private _source: Observable<T> | undefined = undefined;

constructor(urlConfigOrSource: string | WebSocketSubjectConfig<T> | Observable<T>, destination?: Observer<T>) {
constructor(urlConfigOrSource: string | WebSocketSubjectConfig<T>) {
super();
if (urlConfigOrSource instanceof Observable) {
this.destination = destination;
this._source = urlConfigOrSource as Observable<T>;
} else {
const userConfig = typeof urlConfigOrSource === 'string' ? { url: urlConfigOrSource } : urlConfigOrSource;
this._config = {
...DEFAULT_WEBSOCKET_CONFIG,
// Setting this here because a previous version of this allowed
// WebSocket to be polyfilled later than DEFAULT_WEBSOCKET_CONFIG
// was defined.
WebSocketCtor: WebSocket,
...userConfig,
};

if (!this._config.WebSocketCtor) {
throw new Error('no WebSocket constructor can be found');
}
const userConfig = typeof urlConfigOrSource === 'string' ? { url: urlConfigOrSource } : urlConfigOrSource;
this._config = {
...DEFAULT_WEBSOCKET_CONFIG,
// Setting this here because a previous version of this allowed
// WebSocket to be polyfilled later than DEFAULT_WEBSOCKET_CONFIG
// was defined.
WebSocketCtor: WebSocket,
...userConfig,
};

this._output = new Subject<T>();
this.destination = new ReplaySubject();
if (!this._config.WebSocketCtor) {
throw new Error('no WebSocket constructor can be found');
}

this._output = new Subject<T>();
this.destination = new ReplaySubject();
}

private _resetState() {
Expand Down Expand Up @@ -339,15 +333,15 @@ export class WebSocketSubject<T> extends Subject<T> {
}

next(value: T) {
this.destination?.next?.(value);
this.destination.next(value);
}

error(err: any) {
this.destination?.error?.(err);
this.destination.error(err);
}

complete() {
this.destination?.complete?.();
this.destination.complete();
}

/** @internal */
Expand Down

0 comments on commit 5d0c71d

Please sign in to comment.