Skip to content

Commit

Permalink
refactor: move the typed events to @socket.io/component-emitter
Browse files Browse the repository at this point in the history
The typed events have been moved to [1] in order to remove the
intermediary class and reduce the bundle size.

Diff: socketio/emitter@2.0.0...3.0.0

[1]: https://github.com/socketio/emitter/
  • Loading branch information
darrachequesne committed Oct 14, 2021
1 parent a9e5b85 commit 91b948b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 413 deletions.
7 changes: 4 additions & 3 deletions lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Backoff from "backo2";
import {
DefaultEventsMap,
EventsMap,
StrictEventEmitter,
} from "./typed-events.js";
Emitter,
} from "@socket.io/component-emitter";
import debugModule from "debug"; // debug()

const debug = debugModule("socket.io-client:manager"); // debug()
Expand Down Expand Up @@ -100,7 +100,7 @@ interface ManagerReservedEvents {
export class Manager<
ListenEvents extends EventsMap = DefaultEventsMap,
EmitEvents extends EventsMap = ListenEvents
> extends StrictEventEmitter<{}, {}, ManagerReservedEvents> {
> extends Emitter<{}, {}, ManagerReservedEvents> {
/**
* The Engine.IO client instance
*
Expand Down Expand Up @@ -353,6 +353,7 @@ export class Manager<
debug("connect attempt timed out after %d", timeout);
openSubDestroy();
socket.close();
// @ts-ignore
socket.emit("error", new Error("timeout"));
}, timeout);

Expand Down
5 changes: 2 additions & 3 deletions lib/on.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type * as Emitter from "component-emitter";
import { StrictEventEmitter } from "./typed-events.js";
import { Emitter } from "@socket.io/component-emitter";

export function on(
obj: Emitter | StrictEventEmitter<any, any>,
obj: Emitter<any, any>,
ev: string,
fn: (err?: any) => any
): VoidFunction {
Expand Down
6 changes: 3 additions & 3 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
EventNames,
EventParams,
EventsMap,
StrictEventEmitter,
} from "./typed-events.js";
Emitter,
} from "@socket.io/component-emitter";
import debugModule from "debug"; // debug()

const debug = debugModule("socket.io-client:socket"); // debug()
Expand Down Expand Up @@ -47,7 +47,7 @@ interface SocketReservedEvents {
export class Socket<
ListenEvents extends EventsMap = DefaultEventsMap,
EmitEvents extends EventsMap = ListenEvents
> extends StrictEventEmitter<ListenEvents, EmitEvents, SocketReservedEvents> {
> extends Emitter<ListenEvents, EmitEvents, SocketReservedEvents> {
public readonly io: Manager<ListenEvents, EmitEvents>;

public id: string;
Expand Down
210 changes: 0 additions & 210 deletions lib/typed-events.ts

This file was deleted.

Loading

0 comments on commit 91b948b

Please sign in to comment.