wenay-common 1.0.182 → 1.0.183
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.
- package/lib/Common/Listen.d.ts +11 -15
- package/lib/Common/Listen.js +16 -6
- package/lib/test.d.ts +1 -1
- package/lib/test.js +15 -43
- package/package.json +1 -1
package/lib/Common/Listen.d.ts
CHANGED
|
@@ -33,22 +33,20 @@ export declare function funcListenCallback<T extends any[]>(a: (e: (tr222<T> | n
|
|
|
33
33
|
getAllKeys: IterableIterator<any>;
|
|
34
34
|
};
|
|
35
35
|
type tr2<T extends (...a: any[]) => any> = (a: Parameters<T>[0]) => void;
|
|
36
|
+
type tr2a<T extends (...a: any[]) => any> = (...a: Parameters<T>) => void;
|
|
36
37
|
type t1<T extends any[] = any[]> = ReturnType<typeof funcListenCallback<T>>;
|
|
37
|
-
type
|
|
38
|
-
export declare function
|
|
38
|
+
type tta = tr2a<Parameters<t1["addListen"]>[0]>;
|
|
39
|
+
export declare function funcListenBySocket2<Z extends any[] = any[]>(e: t1<Z>, d?: {
|
|
39
40
|
readonly status?: () => boolean;
|
|
40
|
-
readonly
|
|
41
|
+
readonly addListenClose?: t1<any>;
|
|
42
|
+
readonly stop?: (x: tta) => any;
|
|
43
|
+
readonly paramsModify?: (...e: Parameters<tta>) => any[];
|
|
41
44
|
}): {
|
|
42
|
-
callback: (z: (
|
|
45
|
+
callback: (z: (...params: Parameters<tr2a<tr222<Z>>>) => void) => void;
|
|
43
46
|
removeCallback: () => boolean;
|
|
44
47
|
};
|
|
45
|
-
export declare function
|
|
46
|
-
|
|
47
|
-
readonly addListenClose?: t1<any>;
|
|
48
|
-
readonly stop?: (x: tt) => any;
|
|
49
|
-
readonly paramsModify?: (...e: Parameters<tt>) => any[];
|
|
50
|
-
}): {
|
|
51
|
-
callback: (z: (...params: Parameters<(a: Z[0]) => void>) => void) => void;
|
|
48
|
+
export declare function funcListenBySocket3<Z extends any[] = any[]>(e: t1<Z>, options: Omit<Parameters<typeof funcListenBySocket2>[1], "paramsModify">): {
|
|
49
|
+
callback: (z: (...params: Parameters<tr2<tr222<Z>>>) => void) => void;
|
|
52
50
|
removeCallback: () => boolean;
|
|
53
51
|
};
|
|
54
52
|
export declare function funcListenBySocket<Z extends any[] = any[]>(e: ReturnType<typeof funcListenCallback<Z>>, status: () => boolean, onStop?: ReturnType<typeof funcListenCallback<any>>): {
|
|
@@ -83,10 +81,8 @@ export declare function DeepCompareKeys<T, T2 extends obj, T3 extends unknown>(o
|
|
|
83
81
|
[k: string]: any;
|
|
84
82
|
} | NonNullable<T> | trr2<T> | null;
|
|
85
83
|
export declare function deepModifyByListenSocket<T>(obj: T, status: () => boolean): ttt<T>;
|
|
86
|
-
export declare function deepModifyByListenSocket2<T>(obj: T, data:
|
|
87
|
-
|
|
88
|
-
addListenClose?: t1<any>;
|
|
89
|
-
}): ttt<T>;
|
|
84
|
+
export declare function deepModifyByListenSocket2<T>(obj: T, data: Parameters<typeof funcListenBySocket2>[1]): ttt<T>;
|
|
85
|
+
export declare function deepModifyByListenSocket3<T>(obj: T, data: Parameters<typeof funcListenBySocket3>[1]): ttt<T>;
|
|
90
86
|
export declare const funcListenBySocketObj: typeof deepModifyByListenSocket;
|
|
91
87
|
export declare function PromiseArrayListen<T extends any = unknown>(array: ((() => Promise<T>) | (() => any) | Promise<T>)[]): {
|
|
92
88
|
listenOk: (a: (...d: [data: T, i: number, countOk: number, countError: number, count: number]) => any) => () => void;
|
package/lib/Common/Listen.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.funcListenBySocketObj = exports.funcListenBySocket1 = void 0;
|
|
|
4
4
|
exports.funcListenCallbackBase = funcListenCallbackBase;
|
|
5
5
|
exports.funcListenCallbackFast = funcListenCallbackFast;
|
|
6
6
|
exports.funcListenCallback = funcListenCallback;
|
|
7
|
-
exports.funcListenBySocket3 = funcListenBySocket3;
|
|
8
7
|
exports.funcListenBySocket2 = funcListenBySocket2;
|
|
8
|
+
exports.funcListenBySocket3 = funcListenBySocket3;
|
|
9
9
|
exports.funcListenBySocket = funcListenBySocket;
|
|
10
10
|
exports.UseListen = UseListen;
|
|
11
11
|
exports.CompareKeys = CompareKeys;
|
|
@@ -14,6 +14,7 @@ exports.DeepCompareKeys2 = DeepCompareKeys2;
|
|
|
14
14
|
exports.DeepCompareKeys = DeepCompareKeys;
|
|
15
15
|
exports.deepModifyByListenSocket = deepModifyByListenSocket;
|
|
16
16
|
exports.deepModifyByListenSocket2 = deepModifyByListenSocket2;
|
|
17
|
+
exports.deepModifyByListenSocket3 = deepModifyByListenSocket3;
|
|
17
18
|
exports.PromiseArrayListen = PromiseArrayListen;
|
|
18
19
|
exports.socketBuffer3 = socketBuffer3;
|
|
19
20
|
exports.funcListenCallbackSnapshot = funcListenCallbackSnapshot;
|
|
@@ -76,10 +77,8 @@ function funcListenCallbackFast(a) {
|
|
|
76
77
|
function funcListenCallback(a, event, fast = true) {
|
|
77
78
|
return funcListenCallbackBase(a, { event, fast });
|
|
78
79
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
function funcListenBySocket2(e, { stop, addListenClose, status, paramsModify }) {
|
|
80
|
+
function funcListenBySocket2(e, d) {
|
|
81
|
+
const { stop, addListenClose, status, paramsModify } = d ?? {};
|
|
83
82
|
const { addListen, removeListen, count } = e;
|
|
84
83
|
let last = null;
|
|
85
84
|
let r2 = null;
|
|
@@ -109,7 +108,7 @@ function funcListenBySocket2(e, { stop, addListenClose, status, paramsModify })
|
|
|
109
108
|
if (paramsModify)
|
|
110
109
|
ta = (...a) => z(...paramsModify(...a));
|
|
111
110
|
if (status)
|
|
112
|
-
r2 = (a) => { status() ? ta(a) : removeListen(r2); };
|
|
111
|
+
r2 = (...a) => { status() ? ta(...a) : removeListen(r2); };
|
|
113
112
|
else
|
|
114
113
|
r2 = ta;
|
|
115
114
|
addListen(r2);
|
|
@@ -120,6 +119,14 @@ function funcListenBySocket2(e, { stop, addListenClose, status, paramsModify })
|
|
|
120
119
|
removeCallback
|
|
121
120
|
};
|
|
122
121
|
}
|
|
122
|
+
function funcListenBySocket3(e, options) {
|
|
123
|
+
const r = funcListenBySocket2(e, { ...options, paramsModify: e => [e] });
|
|
124
|
+
const callback = r.callback;
|
|
125
|
+
return {
|
|
126
|
+
callback,
|
|
127
|
+
removeCallback: r.removeCallback
|
|
128
|
+
};
|
|
129
|
+
}
|
|
123
130
|
function funcListenBySocket(e, status, onStop) {
|
|
124
131
|
const { addListen, removeListen, count } = e;
|
|
125
132
|
let x = null;
|
|
@@ -206,6 +213,9 @@ function deepModifyByListenSocket(obj, status) {
|
|
|
206
213
|
function deepModifyByListenSocket2(obj, data) {
|
|
207
214
|
return DeepCompareKeys(obj, funcListenCallbackBase(e => { }), e => funcListenBySocket2(e, data));
|
|
208
215
|
}
|
|
216
|
+
function deepModifyByListenSocket3(obj, data) {
|
|
217
|
+
return DeepCompareKeys(obj, funcListenCallbackBase(e => { }), e => funcListenBySocket3(e, data));
|
|
218
|
+
}
|
|
209
219
|
exports.funcListenBySocketObj = deepModifyByListenSocket;
|
|
210
220
|
function PromiseArrayListen(array) {
|
|
211
221
|
let ok = 0, error = 0;
|
package/lib/test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/lib/test.js
CHANGED
|
@@ -1,47 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
map.set("z", ff);
|
|
18
|
-
ttt(...par);
|
|
19
|
-
map.set("v", ff);
|
|
20
|
-
ttt(...par);
|
|
21
|
-
map.set("zx", ff);
|
|
22
|
-
ttt(...par);
|
|
23
|
-
map.set("rt", ff);
|
|
24
|
-
map.set("xd", ff);
|
|
25
|
-
map.set("fd", ff);
|
|
26
|
-
ttt(...par);
|
|
27
|
-
map.set("frt", ff);
|
|
28
|
-
map.set("fxd", ff);
|
|
29
|
-
map.set("ffd", ff);
|
|
30
|
-
ttt(...par);
|
|
31
|
-
const ar = [...map.values()];
|
|
32
|
-
ar.length = 1;
|
|
33
|
-
console.time("zz");
|
|
34
|
-
let r = (...a) => {
|
|
35
|
-
for (let i = 0; i < ar.length; i++) {
|
|
36
|
-
ar[i](...a);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const tr = (...a) => {
|
|
40
|
-
};
|
|
41
|
-
r = null;
|
|
42
|
-
for (let i = 0; i < l; i++) {
|
|
43
|
-
r?.(...par);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Listen_1 = require("./Common/Listen");
|
|
4
|
+
const common_1 = require("./Common/common");
|
|
5
|
+
async function test() {
|
|
6
|
+
const [setA, listenA] = (0, Listen_1.UseListen)();
|
|
7
|
+
const [setStop, listenStop] = (0, Listen_1.UseListen)();
|
|
8
|
+
const r = (0, Listen_1.funcListenBySocket3)(listenA, { addListenClose: listenStop });
|
|
9
|
+
r.callback((...a) => {
|
|
10
|
+
console.log(a);
|
|
11
|
+
});
|
|
12
|
+
for (let i = 0; i < 10; i++) {
|
|
13
|
+
await (0, common_1.sleepAsync)(200);
|
|
14
|
+
setA(6, [3.4]);
|
|
15
|
+
if (i == 5)
|
|
16
|
+
setStop();
|
|
44
17
|
}
|
|
45
|
-
console.timeEnd("zz");
|
|
46
18
|
}
|
|
47
19
|
test();
|