socket-function 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,7 @@ export declare class SocketFunction {
64
64
  private static socketCache;
65
65
  static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
66
66
  private static callFromGuid;
67
+ /** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback). */
67
68
  static onNextDisconnect(nodeId: string, callback: () => void): void;
68
69
  static getLastDisconnectTime(nodeId: string): number | undefined;
69
70
  static isNodeConnected(nodeId: string): boolean;
package/SocketFunction.ts CHANGED
@@ -289,6 +289,7 @@ export class SocketFunction {
289
289
  }
290
290
  }
291
291
 
292
+ /** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback). */
292
293
  public static onNextDisconnect(nodeId: string, callback: () => void) {
293
294
  (async () => {
294
295
  let factory = await getCallFactory(nodeId);
package/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare module "socket-function/SocketFunction" {
73
73
  private static socketCache;
74
74
  static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
75
75
  private static callFromGuid;
76
+ /** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback). */
76
77
  static onNextDisconnect(nodeId: string, callback: () => void): void;
77
78
  static getLastDisconnectTime(nodeId: string): number | undefined;
78
79
  static isNodeConnected(nodeId: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -145,9 +145,9 @@ export async function createCallFactory(
145
145
  localNodeId
146
146
  };
147
147
 
148
- let disconnectCallbacks: (() => void)[] = [];
148
+ let disconnectCallbacks = new Set<() => void>();
149
149
  function onNextDisconnect(callback: () => void): void {
150
- disconnectCallbacks.push(callback);
150
+ disconnectCallbacks.add(callback);
151
151
  }
152
152
 
153
153
  let callFactory: CallFactory = {
@@ -315,7 +315,7 @@ export async function createCallFactory(
315
315
  }
316
316
 
317
317
  let callbacks = disconnectCallbacks;
318
- disconnectCallbacks = [];
318
+ disconnectCallbacks = new Set();
319
319
  for (let callback of callbacks) {
320
320
  try {
321
321
  callback();