From 93932150aca9090a659c3c878e7061e73b1bc13f Mon Sep 17 00:00:00 2001 From: nayounsang Date: Wed, 25 Sep 2024 13:29:41 +0900 Subject: [PATCH 1/4] comment: write js docs in on --- packages/socket.io-component-emitter/lib/cjs/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/socket.io-component-emitter/lib/cjs/index.d.ts b/packages/socket.io-component-emitter/lib/cjs/index.d.ts index 49a74e142d..161d0dae90 100644 --- a/packages/socket.io-component-emitter/lib/cjs/index.d.ts +++ b/packages/socket.io-component-emitter/lib/cjs/index.d.ts @@ -82,6 +82,11 @@ export class Emitter< * * @param ev Name of the event * @param listener Callback function + * @reserved + * - "connect": This event is fired by the Socket instance upon connection **and** reconnection. + * - "connect_error": This event is fired upon connection failure. + * - "disconnect": This event is fired upon disconnection. + * @see [client-api-events](https://socket.io/docs/v4/client-api/#events-1) */ on>( ev: Ev, From 1eeac1b42ce540908cd6c86e922918a8b0d9076c Mon Sep 17 00:00:00 2001 From: nayounsang Date: Wed, 23 Oct 2024 21:33:48 +0900 Subject: [PATCH 2/4] Revert "comment: write js docs in on" This reverts commit 93932150aca9090a659c3c878e7061e73b1bc13f. --- packages/socket.io-component-emitter/lib/cjs/index.d.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/socket.io-component-emitter/lib/cjs/index.d.ts b/packages/socket.io-component-emitter/lib/cjs/index.d.ts index 161d0dae90..49a74e142d 100644 --- a/packages/socket.io-component-emitter/lib/cjs/index.d.ts +++ b/packages/socket.io-component-emitter/lib/cjs/index.d.ts @@ -82,11 +82,6 @@ export class Emitter< * * @param ev Name of the event * @param listener Callback function - * @reserved - * - "connect": This event is fired by the Socket instance upon connection **and** reconnection. - * - "connect_error": This event is fired upon connection failure. - * - "disconnect": This event is fired upon disconnection. - * @see [client-api-events](https://socket.io/docs/v4/client-api/#events-1) */ on>( ev: Ev, From 5dbedffa673813e5c5c119ef7581e60a0802b9c2 Mon Sep 17 00:00:00 2001 From: nayounsang Date: Wed, 23 Oct 2024 22:15:39 +0900 Subject: [PATCH 3/4] comment: overwrite on method & write addtional js docs --- packages/socket.io-client/lib/socket.ts | 36 +++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/socket.io-client/lib/socket.ts b/packages/socket.io-client/lib/socket.ts index 973bafb32f..94d3271b02 100644 --- a/packages/socket.io-client/lib/socket.ts +++ b/packages/socket.io-client/lib/socket.ts @@ -7,6 +7,8 @@ import { EventParams, EventsMap, Emitter, + ReservedOrUserEventNames, + ReservedOrUserListener, } from "@socket.io/component-emitter"; import debugModule from "debug"; // debug() @@ -18,6 +20,8 @@ type PrependTimeoutError = { : T[K]; }; +interface ReservedEvents extends EventsMap {} + /** * Utility type to decorate the acknowledgement callbacks with a timeout error. * @@ -116,7 +120,7 @@ interface SocketReservedEvents { connect_error: (err: Error) => void; disconnect: ( reason: Socket.DisconnectReason, - description?: DisconnectDescription, + description?: DisconnectDescription ) => void; } @@ -551,7 +555,7 @@ export class Socket< debug( "packet [%d] is discarded after %d tries", packet.id, - packet.tryCount, + packet.tryCount ); this._queue.shift(); if (ack) { @@ -588,7 +592,7 @@ export class Socket< if (packet.pending && !force) { debug( "packet [%d] has already been sent and is waiting for an ack", - packet.id, + packet.id ); return; } @@ -662,7 +666,7 @@ export class Socket< */ private onclose( reason: Socket.DisconnectReason, - description?: DisconnectDescription, + description?: DisconnectDescription ): void { debug("close (%s)", reason); this.connected = false; @@ -680,7 +684,7 @@ export class Socket< private _clearAcks() { Object.keys(this.acks).forEach((id) => { const isBuffered = this.sendBuffer.some( - (packet) => String(packet.id) === id, + (packet) => String(packet.id) === id ); if (!isBuffered) { // note: handlers that do not accept an error as first argument are ignored here @@ -713,8 +717,8 @@ export class Socket< this.emitReserved( "connect_error", new Error( - "It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)", - ), + "It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)" + ) ); } break; @@ -964,7 +968,7 @@ export class Socket< * @returns self */ public timeout( - timeout: number, + timeout: number ): Socket> { this.flags.timeout = timeout; return this; @@ -1145,6 +1149,22 @@ export class Socket< } } } + + /** + * @param ev Name of the event + * @param listener Callback function + * @reserved + * - `connect`: This event is fired by the Socket instance upon connection **and** reconnection. + * - `connect_error`: This event is fired upon connection failure. + * - `disconnect`: This event is fired upon disconnection. + * @see [client-api-events](https://socket.io/docs/v4/client-api/#events-1) + */ + public on>( + ev: Ev, + listener: ReservedOrUserListener + ): this { + return super.on(ev, listener); + } } export namespace Socket { From 9cfe5ad9d47b8fa99c848b338ce69173f4b8ab33 Mon Sep 17 00:00:00 2001 From: nayounsang Date: Wed, 23 Oct 2024 22:31:13 +0900 Subject: [PATCH 4/4] fix: prettier format --- packages/socket.io-client/lib/socket.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/socket.io-client/lib/socket.ts b/packages/socket.io-client/lib/socket.ts index 94d3271b02..425af41e03 100644 --- a/packages/socket.io-client/lib/socket.ts +++ b/packages/socket.io-client/lib/socket.ts @@ -120,7 +120,7 @@ interface SocketReservedEvents { connect_error: (err: Error) => void; disconnect: ( reason: Socket.DisconnectReason, - description?: DisconnectDescription + description?: DisconnectDescription, ) => void; } @@ -555,7 +555,7 @@ export class Socket< debug( "packet [%d] is discarded after %d tries", packet.id, - packet.tryCount + packet.tryCount, ); this._queue.shift(); if (ack) { @@ -592,7 +592,7 @@ export class Socket< if (packet.pending && !force) { debug( "packet [%d] has already been sent and is waiting for an ack", - packet.id + packet.id, ); return; } @@ -666,7 +666,7 @@ export class Socket< */ private onclose( reason: Socket.DisconnectReason, - description?: DisconnectDescription + description?: DisconnectDescription, ): void { debug("close (%s)", reason); this.connected = false; @@ -684,7 +684,7 @@ export class Socket< private _clearAcks() { Object.keys(this.acks).forEach((id) => { const isBuffered = this.sendBuffer.some( - (packet) => String(packet.id) === id + (packet) => String(packet.id) === id, ); if (!isBuffered) { // note: handlers that do not accept an error as first argument are ignored here @@ -717,8 +717,8 @@ export class Socket< this.emitReserved( "connect_error", new Error( - "It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)" - ) + "It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)", + ), ); } break; @@ -968,7 +968,7 @@ export class Socket< * @returns self */ public timeout( - timeout: number + timeout: number, ): Socket> { this.flags.timeout = timeout; return this; @@ -1161,7 +1161,7 @@ export class Socket< */ public on>( ev: Ev, - listener: ReservedOrUserListener + listener: ReservedOrUserListener, ): this { return super.on(ev, listener); }