wenay-common 1.0.159 → 1.0.161

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.
@@ -1,7 +1,5 @@
1
1
  type tr222<T extends any[]> = (...r: T) => void;
2
- export declare function funcListenCallback<T extends any[]>(a: (e: tr222<T>) => (void | (() => void)), event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallback<T>>) => void): {
3
- lastUpdate: () => Date | null;
4
- lastUpdateMs: () => number | null;
2
+ export declare function funcListenCallback<T extends any[]>(a: (e: (tr222<T> | null)) => (void | (() => void)), event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallback<T>>) => void, fast?: boolean): {
5
3
  isRun: () => boolean;
6
4
  run: () => (() => void) | null;
7
5
  close: () => void;
@@ -36,8 +34,6 @@ export declare const funcListenBySocket1: typeof funcListenBySocket;
36
34
  export declare function UseListen<T extends any[]>(data?: {
37
35
  event?: Parameters<typeof funcListenCallback<T>>[1];
38
36
  }): readonly [(...e: T) => void | undefined, {
39
- lastUpdate: () => Date | null;
40
- lastUpdateMs: () => number | null;
41
37
  isRun: () => boolean;
42
38
  run: () => (() => void) | null;
43
39
  close: () => void;
@@ -46,7 +42,7 @@ export declare function UseListen<T extends any[]>(data?: {
46
42
  count: () => number;
47
43
  }];
48
44
  type tDeepKeys<T, T2 extends object, T3 extends any> = {
49
- [K in keyof T]: T[K] extends T2 ? T3 : T[K] extends object ? T[K] extends (a?: any) => any ? T[K] : tDeepKeys<T[K], T2, T3> : T[K];
45
+ [K in keyof T]: T[K] extends T2 ? T3 : T[K] extends object ? T[K] extends (a?: any) => any ? T[K] : T[K] extends (...a: any[]) => any ? T[K] : tDeepKeys<T[K], T2, T3> : T[K];
50
46
  };
51
47
  type obj = {
52
48
  [k: string]: any;
@@ -94,8 +90,6 @@ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | a
94
90
  snapshot: () => T3 | undefined;
95
91
  memo: T4;
96
92
  listenA: {
97
- lastUpdate: () => Date | null;
98
- lastUpdateMs: () => number | null;
99
93
  isRun: () => boolean;
100
94
  run: () => (() => void) | null;
101
95
  close: () => void;
@@ -13,27 +13,48 @@ exports.deepModifyByListenSocket2 = deepModifyByListenSocket2;
13
13
  exports.PromiseArrayListen = PromiseArrayListen;
14
14
  exports.socketBuffer3 = socketBuffer3;
15
15
  exports.funcListenCallbackSnapshot = funcListenCallbackSnapshot;
16
- function funcListenCallback(a, event) {
16
+ function funcListenCallback(a, event, fast = true) {
17
17
  const obj = new Map;
18
18
  let close = null;
19
- let lastUpdate = null;
19
+ let lastSize = 0;
20
+ const checkFast = () => {
21
+ if (!fast)
22
+ return;
23
+ const size = obj.size;
24
+ if (lastSize > 2 && size > 2)
25
+ return;
26
+ if (obj.size == 0) {
27
+ a(null);
28
+ return;
29
+ }
30
+ const ar = [];
31
+ obj.forEach(e => ar.push(e));
32
+ if (obj.size == 1)
33
+ a((...e) => { ar[0](...e); });
34
+ if (obj.size == 2)
35
+ a((...e) => { ar[0](...e); ar[1](...e); });
36
+ if (obj.size > 2)
37
+ a((...e) => { obj.forEach(z => z(...e)); });
38
+ };
20
39
  const run = () => close = ((a((...z) => {
21
- lastUpdate = Date.now();
22
40
  obj.forEach(e => e(...z));
23
41
  })) ?? null);
24
42
  const api = {
25
- lastUpdate: () => lastUpdate != null ? new Date(lastUpdate) : lastUpdate,
26
- lastUpdateMs: () => lastUpdate,
27
43
  isRun: () => close != null,
28
44
  run,
29
- close: () => { close?.(); close = null; },
45
+ close: () => {
46
+ close?.();
47
+ close = null;
48
+ },
30
49
  addListen: (a) => {
31
50
  obj.set(a, a);
51
+ checkFast();
32
52
  event?.("add", obj.size, api);
33
53
  return () => api.removeListen(a);
34
54
  },
35
55
  removeListen: (a) => {
36
56
  obj.delete(a);
57
+ checkFast();
37
58
  event?.("remove", obj.size, api);
38
59
  },
39
60
  count: () => obj.size
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonJS",
4
+ "target": "esnext"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wenay-common",
3
- "version": "1.0.159",
3
+ "version": "1.0.161",
4
4
  "description": "Common library",
5
5
  "strict": true,
6
6
  "main": "lib/index.js",