wenay-common2 1.0.46 → 1.0.49
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/README.md +51 -37
- package/lib/Common/Color.d.ts +3 -0
- package/lib/Common/Color.js +4 -0
- package/lib/Common/ObserveAll2/index.d.ts +2 -0
- package/lib/Common/ObserveAll2/index.js +18 -0
- package/lib/Common/ObserveAll2/reactive2.d.ts +33 -0
- package/lib/Common/ObserveAll2/reactive2.js +254 -0
- package/lib/Common/ObserveAll2/store.d.ts +98 -0
- package/lib/Common/ObserveAll2/store.js +381 -0
- package/lib/Common/Time.d.ts +8 -0
- package/lib/Common/Time.js +41 -14
- package/lib/Common/async/PromiseArrayListen.d.ts +3 -3
- package/lib/Common/async/PromiseArrayListen.js +10 -13
- package/lib/Common/async/createIterableObject.js +1 -1
- package/lib/Common/async/waitRun.d.ts +11 -4
- package/lib/Common/async/waitRun.js +74 -44
- package/lib/Common/core/Decorator.d.ts +3 -1
- package/lib/Common/core/Decorator.js +5 -2
- package/lib/Common/core/common.d.ts +25 -7
- package/lib/Common/core/common.js +114 -34
- package/lib/Common/data/ByteStream.d.ts +1 -1
- package/lib/Common/data/ByteStream.js +21 -8
- package/lib/Common/data/List.d.ts +5 -0
- package/lib/Common/data/List.js +13 -4
- package/lib/Common/data/ListNodeAnd.js +2 -2
- package/lib/Common/data/objectPath.d.ts +4 -0
- package/lib/Common/data/objectPath.js +8 -3
- package/lib/Common/events/Listen.d.ts +1 -55
- package/lib/Common/events/Listen.js +15 -154
- package/lib/Common/events/Listen2.d.ts +1 -0
- package/lib/Common/events/Listen2.js +17 -0
- package/lib/Common/events/Listen3.d.ts +197 -0
- package/lib/Common/events/Listen3.js +249 -0
- package/lib/Common/events/SocketBuffer.d.ts +14 -9
- package/lib/Common/events/SocketServerHook.d.ts +26 -13
- package/lib/Common/events/SocketServerHook.js +2 -1
- package/lib/Common/events/UseListenTransform.d.ts +10 -5
- package/lib/Common/events/event.d.ts +12 -0
- package/lib/Common/events/event.js +10 -6
- package/lib/Common/events/joinListens.d.ts +2 -0
- package/lib/Common/events/joinListens.js +13 -12
- package/lib/Common/funcTimeWait.d.ts +28 -0
- package/lib/Common/funcTimeWait.js +18 -1
- package/lib/Common/isProxy.d.ts +1 -0
- package/lib/Common/isProxy.js +2 -0
- package/lib/Common/node_console.d.ts +2 -0
- package/lib/Common/node_console.js +3 -76
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.d.ts +2 -0
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.js +63 -30
- package/lib/Common/rcp/listen-deep.d.ts +13 -5
- package/lib/Common/rcp/listen-socket.d.ts +21 -3
- package/lib/Common/rcp/listen-socket.js +126 -17
- package/lib/Common/rcp/oldCommonsServer.d.ts +1 -1
- package/lib/Common/rcp/oldCommonsServer.js +15 -1
- package/lib/Common/rcp/old/320/241ommonsServerMini.js +1 -0
- package/lib/Common/rcp/rpc-caps.d.ts +10 -0
- package/lib/Common/rcp/rpc-caps.js +16 -0
- package/lib/Common/rcp/rpc-client.d.ts +23 -1
- package/lib/Common/rcp/rpc-client.js +306 -25
- package/lib/Common/rcp/rpc-clientHub.d.ts +7 -1
- package/lib/Common/rcp/rpc-clientHub.js +25 -2
- package/lib/Common/rcp/rpc-index.d.ts +3 -0
- package/lib/Common/rcp/rpc-index.js +3 -0
- package/lib/Common/rcp/rpc-inproc.d.ts +17 -0
- package/lib/Common/rcp/rpc-inproc.js +30 -0
- package/lib/Common/rcp/rpc-off.d.ts +10 -0
- package/lib/Common/rcp/rpc-off.js +22 -0
- package/lib/Common/rcp/rpc-protocol.d.ts +6 -0
- package/lib/Common/rcp/rpc-protocol.js +4 -2
- package/lib/Common/rcp/rpc-server-auto.d.ts +14 -3
- package/lib/Common/rcp/rpc-server-auto.js +81 -6
- package/lib/Common/rcp/rpc-server.d.ts +17 -2
- package/lib/Common/rcp/rpc-server.js +127 -31
- package/lib/Common/rcp/rpc-shape.d.ts +17 -0
- package/lib/Common/rcp/rpc-shape.js +42 -0
- package/lib/Common/rcp/rpc-walk.js +29 -11
- package/lib/Exchange/Bars.d.ts +3 -0
- package/lib/Exchange/Bars.js +4 -1
- package/lib/Exchange/CParams.d.ts +2 -0
- package/lib/Exchange/CParams.js +21 -14
- package/lib/Exchange/MarketData.d.ts +6 -0
- package/lib/Exchange/MarketData.js +4 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/server/WebHook3.js +22 -9
- package/package.json +3 -1
|
@@ -4,7 +4,10 @@ exports.ByteStreamR = exports.ByteStreamW = exports.Nullable = void 0;
|
|
|
4
4
|
exports.nullable = nullable;
|
|
5
5
|
function createCopyOfBuffer(src, length = src.byteLength) {
|
|
6
6
|
let dst = new ArrayBuffer(length);
|
|
7
|
-
|
|
7
|
+
const bytes = src instanceof DataView
|
|
8
|
+
? new Uint8Array(src.buffer, src.byteOffset, Math.min(src.byteLength, length))
|
|
9
|
+
: new Uint8Array(src, 0, Math.min(src.byteLength, length));
|
|
10
|
+
new Uint8Array(dst).set(bytes);
|
|
8
11
|
return dst;
|
|
9
12
|
}
|
|
10
13
|
class Nullable {
|
|
@@ -45,7 +48,7 @@ class ByteStreamW {
|
|
|
45
48
|
_isThrowable = true;
|
|
46
49
|
_buffer() { return this._view?.buffer; }
|
|
47
50
|
resize(size) {
|
|
48
|
-
let buf = createCopyOfBuffer(this.
|
|
51
|
+
let buf = createCopyOfBuffer(this._view, size);
|
|
49
52
|
this._view = new DataView(buf);
|
|
50
53
|
}
|
|
51
54
|
constructor(view) {
|
|
@@ -57,7 +60,7 @@ class ByteStreamW {
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
get length() { return this._pos; }
|
|
60
|
-
get data() { return new DataView(this._buffer(),
|
|
63
|
+
get data() { return new DataView(this._buffer(), this._view.byteOffset, this._pos); }
|
|
61
64
|
noThrow() { let other = new ByteStreamW(this._view); other._pos = this._pos; other._isThrowable = false; return other; }
|
|
62
65
|
_ensureAllocation(bytes) {
|
|
63
66
|
let minSize = this._pos + bytes;
|
|
@@ -166,7 +169,15 @@ class ByteStreamW {
|
|
|
166
169
|
let typeInfo = getNumericTypeInfo(type);
|
|
167
170
|
if (!typeInfo)
|
|
168
171
|
throw ("Wrong type: " + type);
|
|
169
|
-
return (stream, value) => {
|
|
172
|
+
return (stream, value) => {
|
|
173
|
+
if (isNullable) {
|
|
174
|
+
if (stream.pushBool(value != null) == null)
|
|
175
|
+
return false;
|
|
176
|
+
if (value == null)
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return stream._push(value, typeInfo.size, typeInfo.integer) != null;
|
|
180
|
+
};
|
|
170
181
|
}
|
|
171
182
|
pushArrayNumeric(array, type, maxlength) {
|
|
172
183
|
return this.pushArrayByFunc(array, this._getWriteFuncForNumeric(type), maxlength);
|
|
@@ -177,10 +188,7 @@ class ByteStreamW {
|
|
|
177
188
|
this._ensureAllocation(length + 4);
|
|
178
189
|
this.pushInt32(length);
|
|
179
190
|
let arrayClass = (array instanceof Int8Array) ? Int8Array : Uint8Array;
|
|
180
|
-
|
|
181
|
-
array = new arrayClass(array.buffer, 0, length);
|
|
182
|
-
}
|
|
183
|
-
new arrayClass(this._buffer()).set(array, this._pos);
|
|
191
|
+
new arrayClass(this._buffer(), this._view.byteOffset + this._pos, length).set(array.subarray(0, length));
|
|
184
192
|
this._pos += length;
|
|
185
193
|
return this;
|
|
186
194
|
}
|
|
@@ -341,6 +349,11 @@ class ByteStreamR_ {
|
|
|
341
349
|
let size = this.readUint32();
|
|
342
350
|
if (size == null)
|
|
343
351
|
return null;
|
|
352
|
+
if (this._pos + size > this._view.byteLength)
|
|
353
|
+
if (this.isThrowable)
|
|
354
|
+
throw ("Array read out of range");
|
|
355
|
+
else
|
|
356
|
+
return null;
|
|
344
357
|
let bufpos = this._view.byteOffset + this._pos;
|
|
345
358
|
const out = new arrayClass(this._view.buffer.slice(bufpos, bufpos + size));
|
|
346
359
|
this._pos += size;
|
|
@@ -24,6 +24,7 @@ export declare class CList<T, TNode extends ListNode<T> = ListNode<T>> implement
|
|
|
24
24
|
get last(): CListNode<T> | undefined;
|
|
25
25
|
get count(): number;
|
|
26
26
|
get length(): number;
|
|
27
|
+
get size(): number;
|
|
27
28
|
readonly [Symbol.iterator]: () => Generator<TNode, void, unknown>;
|
|
28
29
|
constructor(values?: Iterable<T>);
|
|
29
30
|
nodes(): Generator<TNode, void, unknown>;
|
|
@@ -53,6 +54,10 @@ export declare class CList<T, TNode extends ListNode<T> = ListNode<T>> implement
|
|
|
53
54
|
delete(node: ListNode<T>): void;
|
|
54
55
|
deleteFirst(): void;
|
|
55
56
|
deleteLast(): void;
|
|
57
|
+
push(value: T): ListNode<T>;
|
|
58
|
+
unshift(value: T): ListNode<T>;
|
|
59
|
+
pop(): T | undefined;
|
|
60
|
+
shift(): T | undefined;
|
|
56
61
|
clear(): void;
|
|
57
62
|
private validateNode;
|
|
58
63
|
private newNode;
|
package/lib/Common/data/List.js
CHANGED
|
@@ -18,15 +18,20 @@ class CList {
|
|
|
18
18
|
get last() { return this._last; }
|
|
19
19
|
get count() { return this._count; }
|
|
20
20
|
get length() { return this._count; }
|
|
21
|
+
get size() { return this._count; }
|
|
21
22
|
[Symbol.iterator] = this.nodes;
|
|
22
23
|
constructor(values = []) { for (let value of values)
|
|
23
24
|
this.add(value); }
|
|
24
|
-
*nodes() { for (let node = this._first
|
|
25
|
-
yield node;
|
|
25
|
+
*nodes() { for (let node = this._first; node != null;) {
|
|
26
|
+
yield node;
|
|
27
|
+
node = node.next;
|
|
28
|
+
} }
|
|
26
29
|
*values() { for (let node of this)
|
|
27
30
|
yield node.value; }
|
|
28
|
-
*reversedNodes() { for (let node = this._last
|
|
29
|
-
yield node;
|
|
31
|
+
*reversedNodes() { for (let node = this._last; node != null;) {
|
|
32
|
+
yield node;
|
|
33
|
+
node = node.prev;
|
|
34
|
+
} }
|
|
30
35
|
*reversedValues() { for (let node of this.reversedNodes())
|
|
31
36
|
yield node.value; }
|
|
32
37
|
*entries() { let i = 0; for (let node of this.nodes())
|
|
@@ -143,6 +148,10 @@ class CList {
|
|
|
143
148
|
this.delete(this._first); }
|
|
144
149
|
deleteLast() { if (this._last)
|
|
145
150
|
this.delete(this._last); }
|
|
151
|
+
push(value) { return this.addLast(value); }
|
|
152
|
+
unshift(value) { return this.addFirst(value); }
|
|
153
|
+
pop() { let value = this._last?.value; this.deleteLast(); return value; }
|
|
154
|
+
shift() { let value = this._first?.value; this.deleteFirst(); return value; }
|
|
146
155
|
clear() {
|
|
147
156
|
for (let node = this._first; node != null; node = node.next)
|
|
148
157
|
node.list = undefined;
|
|
@@ -68,8 +68,8 @@ class CListNodeAnd extends CBaseList {
|
|
|
68
68
|
isForbidden() { return this._stop; }
|
|
69
69
|
isExists() { return this.isForbidden() || this._prev._stop || this._next._stop; }
|
|
70
70
|
static _Add(prev, next, home, a) { let buf = new CListNodeAnd(prev, next, home); buf.data = a; return buf; }
|
|
71
|
-
AddNext(a) { return a instanceof CListNodeAnd ? a._Init(this, this._next, this) :
|
|
72
|
-
AddPrev(a) { return a instanceof CListNodeAnd ? a._Init(this._prev, this, this) :
|
|
71
|
+
AddNext(a) { return a instanceof CListNodeAnd ? a._Init(this, this._next, this) : arguments.length ? CListNodeAnd._Add(this, this._next, this._home, a) : new CListNodeAnd(this, this._next); }
|
|
72
|
+
AddPrev(a) { return a instanceof CListNodeAnd ? a._Init(this._prev, this, this) : arguments.length ? CListNodeAnd._Add(this._prev, this, this._home, a) : new CListNodeAnd(this._prev, this); }
|
|
73
73
|
AddEnd(a) { return this._stop ? this.AddPrev(a) : this._End().AddNext(a); }
|
|
74
74
|
AddStart(a) { return this._stop ? this.AddNext(a) : this._First().AddPrev(a); }
|
|
75
75
|
forEach(el) {
|
|
@@ -2,10 +2,14 @@ export type ObjectKeyPath<TObject extends object = object, TValue = unknown> = r
|
|
|
2
2
|
export declare function objectSetValueByPath<TObj extends {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}, TVal>(obj: TObj, path: ObjectKeyPath<TObj, TVal>, value: TVal): void;
|
|
5
|
+
export declare const objectSet: typeof objectSetValueByPath;
|
|
5
6
|
export declare function objectGetValueByPath<TObj extends {
|
|
6
7
|
readonly [key: string]: any;
|
|
7
8
|
}, TVal>(object: TObj, path: ObjectKeyPath<TObj, TVal>): TVal;
|
|
9
|
+
export declare const objectGet: typeof objectGetValueByPath;
|
|
8
10
|
export declare function objectDeleteValueByPath<TObj extends {
|
|
9
11
|
readonly [key: string]: any;
|
|
10
12
|
}, TVal>(object: TObj, path: ObjectKeyPath<TObj, TVal>): boolean;
|
|
13
|
+
export declare const objectUnset: typeof objectDeleteValueByPath;
|
|
11
14
|
export declare function iterateDeepObjectEntries<TObj extends object>(obj: TObj, filter?: (key: string, value: unknown, path: ObjectKeyPath<TObj>) => boolean, currentPath?: ObjectKeyPath<TObj>): Generator<[key: string, value: unknown, path: ObjectKeyPath<TObj>]>;
|
|
15
|
+
export declare const deepEntries: typeof iterateDeepObjectEntries;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepEntries = exports.objectUnset = exports.objectGet = exports.objectSet = void 0;
|
|
3
4
|
exports.objectSetValueByPath = objectSetValueByPath;
|
|
4
5
|
exports.objectGetValueByPath = objectGetValueByPath;
|
|
5
6
|
exports.objectDeleteValueByPath = objectDeleteValueByPath;
|
|
@@ -13,10 +14,11 @@ function objectSetValueByPath(obj, path, value) {
|
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
16
|
let val = obj[key];
|
|
16
|
-
if (typeof val != "object")
|
|
17
|
+
if (val == null || typeof val != "object")
|
|
17
18
|
throw "value is not an object: " + val;
|
|
18
19
|
return objectSetValueByPath(val, path.slice(1), value);
|
|
19
20
|
}
|
|
21
|
+
exports.objectSet = objectSetValueByPath;
|
|
20
22
|
function objectGetValueByPath(object, path) {
|
|
21
23
|
if (path.length == 0)
|
|
22
24
|
throw "empty path!";
|
|
@@ -26,10 +28,11 @@ function objectGetValueByPath(object, path) {
|
|
|
26
28
|
let val = object[key];
|
|
27
29
|
if (path.length == 1)
|
|
28
30
|
return val;
|
|
29
|
-
if (typeof val != "object")
|
|
31
|
+
if (val == null || typeof val != "object")
|
|
30
32
|
throw "value is not an object: " + val;
|
|
31
33
|
return objectGetValueByPath(val, path.slice(1));
|
|
32
34
|
}
|
|
35
|
+
exports.objectGet = objectGetValueByPath;
|
|
33
36
|
function objectDeleteValueByPath(object, path) {
|
|
34
37
|
if (path.length == 0)
|
|
35
38
|
throw "empty path!";
|
|
@@ -42,10 +45,11 @@ function objectDeleteValueByPath(object, path) {
|
|
|
42
45
|
return true;
|
|
43
46
|
}
|
|
44
47
|
let val = object[key];
|
|
45
|
-
if (typeof val != "object")
|
|
48
|
+
if (val == null || typeof val != "object")
|
|
46
49
|
throw "value is not an object: " + val;
|
|
47
50
|
return objectDeleteValueByPath(val, path.slice(1));
|
|
48
51
|
}
|
|
52
|
+
exports.objectUnset = objectDeleteValueByPath;
|
|
49
53
|
function* iterateDeepObjectEntries(obj, filter, currentPath = []) {
|
|
50
54
|
if (obj)
|
|
51
55
|
for (let [key, val] of Object.entries(obj)) {
|
|
@@ -57,3 +61,4 @@ function* iterateDeepObjectEntries(obj, filter, currentPath = []) {
|
|
|
57
61
|
yield* iterateDeepObjectEntries(val, filter, keyPath);
|
|
58
62
|
}
|
|
59
63
|
}
|
|
64
|
+
exports.deepEntries = iterateDeepObjectEntries;
|
|
@@ -1,55 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export type NormalizeTuple<T> = T extends any[] ? T : [T];
|
|
3
|
-
type key = string;
|
|
4
|
-
export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), { fast, event, addListenClose }?: {
|
|
5
|
-
event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void;
|
|
6
|
-
fast?: boolean;
|
|
7
|
-
addListenClose?: ReturnType<typeof funcListenCallbackBase<any>>;
|
|
8
|
-
}): {
|
|
9
|
-
func: Listener<NormalizeTuple<T>>;
|
|
10
|
-
isRun: () => boolean;
|
|
11
|
-
run: () => void;
|
|
12
|
-
close: () => void;
|
|
13
|
-
eventClose: (cb: () => void) => () => void;
|
|
14
|
-
removeEventClose: (cb: (() => void)) => void;
|
|
15
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
16
|
-
cbClose?: () => void;
|
|
17
|
-
key?: key;
|
|
18
|
-
}) => () => void;
|
|
19
|
-
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
20
|
-
count: () => number;
|
|
21
|
-
readonly getAllKeys: (Listener<NormalizeTuple<T>> | key)[];
|
|
22
|
-
};
|
|
23
|
-
export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void))): {
|
|
24
|
-
func: Listener<NormalizeTuple<T>>;
|
|
25
|
-
isRun: () => boolean;
|
|
26
|
-
run: () => void;
|
|
27
|
-
close: () => void;
|
|
28
|
-
eventClose: (cb: () => void) => () => void;
|
|
29
|
-
removeEventClose: (cb: () => void) => void;
|
|
30
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
31
|
-
cbClose?: (() => void) | undefined;
|
|
32
|
-
key?: key;
|
|
33
|
-
}) => () => void;
|
|
34
|
-
removeListen: (k: string | Listener<NormalizeTuple<T>> | null) => void;
|
|
35
|
-
count: () => number;
|
|
36
|
-
readonly getAllKeys: (string | Listener<NormalizeTuple<T>>)[];
|
|
37
|
-
};
|
|
38
|
-
export declare const funcListenCallback: typeof funcListenCallbackBase;
|
|
39
|
-
export declare function UseListen<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
40
|
-
func: Listener<NormalizeTuple<T>>;
|
|
41
|
-
isRun: () => boolean;
|
|
42
|
-
run: () => void;
|
|
43
|
-
close: () => void;
|
|
44
|
-
eventClose: (cb: () => void) => () => void;
|
|
45
|
-
removeEventClose: (cb: () => void) => void;
|
|
46
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
47
|
-
cbClose?: (() => void) | undefined;
|
|
48
|
-
key?: key;
|
|
49
|
-
}) => () => void;
|
|
50
|
-
removeListen: (k: string | Listener<NormalizeTuple<T>> | null) => void;
|
|
51
|
-
count: () => number;
|
|
52
|
-
readonly getAllKeys: (string | Listener<NormalizeTuple<T>>)[];
|
|
53
|
-
}];
|
|
54
|
-
export declare function isListenCallback(obj: any): obj is ReturnType<typeof funcListenCallbackBase>;
|
|
55
|
-
export {};
|
|
1
|
+
export * from "./Listen3";
|
|
@@ -1,156 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.isListenCallback = isListenCallback;
|
|
8
|
-
function funcListenCallbackBase(b, { fast = true, event, addListenClose } = {}) {
|
|
9
|
-
const obj = new Map();
|
|
10
|
-
const evClose = new Map();
|
|
11
|
-
const sinh = new Map();
|
|
12
|
-
let a = (...e) => { obj.forEach(z => z(...e)); };
|
|
13
|
-
let close = null;
|
|
14
|
-
let cached = null;
|
|
15
|
-
let closeUnsubscribe = null;
|
|
16
|
-
const getArr = () => cached ?? (cached = Array.from(obj.values()));
|
|
17
|
-
const rebuild = () => {
|
|
18
|
-
cached = null;
|
|
19
|
-
const size = obj.size;
|
|
20
|
-
if (size === 0) {
|
|
21
|
-
a = null;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (size === 1) {
|
|
25
|
-
a = obj.values().next().value;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (size === 2) {
|
|
29
|
-
const [a0, a1] = getArr();
|
|
30
|
-
a = ((...e) => { a0(...e); a1(...e); });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
a = ((...e) => {
|
|
34
|
-
const ar = getArr();
|
|
35
|
-
for (let i = 0, len = ar.length; i < len; i++)
|
|
36
|
-
ar[i](...e);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
const func = (...e) => { a?.(...e); };
|
|
40
|
-
const run = () => {
|
|
41
|
-
close = (b(func) ?? (() => { }));
|
|
42
|
-
if (addListenClose && !closeUnsubscribe) {
|
|
43
|
-
closeUnsubscribe = addListenClose.addListen(() => {
|
|
44
|
-
api.close();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const api = {
|
|
49
|
-
func,
|
|
50
|
-
isRun: () => close !== null,
|
|
51
|
-
run,
|
|
52
|
-
close: () => {
|
|
53
|
-
close?.();
|
|
54
|
-
close = null;
|
|
55
|
-
obj.clear();
|
|
56
|
-
if (fast)
|
|
57
|
-
rebuild();
|
|
58
|
-
sinh.clear();
|
|
59
|
-
evClose.forEach(cb => cb());
|
|
60
|
-
evClose.clear();
|
|
61
|
-
if (closeUnsubscribe) {
|
|
62
|
-
closeUnsubscribe();
|
|
63
|
-
closeUnsubscribe = null;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
eventClose: (cb) => {
|
|
67
|
-
evClose.set(cb, cb);
|
|
68
|
-
return () => { evClose.delete(cb); };
|
|
69
|
-
},
|
|
70
|
-
removeEventClose: (cb) => {
|
|
71
|
-
const e = sinh.get(cb);
|
|
72
|
-
if (e)
|
|
73
|
-
evClose.delete(e);
|
|
74
|
-
sinh.delete(cb);
|
|
75
|
-
evClose.delete(cb);
|
|
76
|
-
},
|
|
77
|
-
addListen: (cb, { cbClose, key } = {}) => {
|
|
78
|
-
const k = key ?? cb;
|
|
79
|
-
obj.set(k, cb);
|
|
80
|
-
if (cbClose) {
|
|
81
|
-
if (evClose.has(k)) {
|
|
82
|
-
const r = evClose.get(k);
|
|
83
|
-
if (r !== cbClose) {
|
|
84
|
-
evClose.delete(r);
|
|
85
|
-
evClose.delete(k);
|
|
86
|
-
sinh.delete(r);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
evClose.set(k, cbClose);
|
|
90
|
-
sinh.set(cbClose, cb);
|
|
91
|
-
}
|
|
92
|
-
if (fast)
|
|
93
|
-
rebuild();
|
|
94
|
-
event?.("add", obj.size, api);
|
|
95
|
-
return () => api.removeListen(k);
|
|
96
|
-
},
|
|
97
|
-
removeListen: (k) => {
|
|
98
|
-
obj.delete(k);
|
|
99
|
-
const e = evClose.get(k);
|
|
100
|
-
if (fast)
|
|
101
|
-
rebuild();
|
|
102
|
-
evClose.delete(k);
|
|
103
|
-
if (e) {
|
|
104
|
-
evClose.delete(e);
|
|
105
|
-
sinh.delete(e);
|
|
106
|
-
}
|
|
107
|
-
event?.("remove", obj.size, api);
|
|
108
|
-
},
|
|
109
|
-
count: () => obj.size,
|
|
110
|
-
get getAllKeys() { return [...obj.keys()]; }
|
|
111
|
-
};
|
|
112
|
-
return api;
|
|
113
|
-
}
|
|
114
|
-
function funcListenCallbackFast(a) {
|
|
115
|
-
return funcListenCallbackBase(a, { fast: true });
|
|
116
|
-
}
|
|
117
|
-
exports.funcListenCallback = funcListenCallbackBase;
|
|
118
|
-
function UseListen(data = { fast: true }) {
|
|
119
|
-
let t;
|
|
120
|
-
const a = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...data });
|
|
121
|
-
a.run();
|
|
122
|
-
t = a.func;
|
|
123
|
-
return [t, a];
|
|
124
|
-
}
|
|
125
|
-
let referenceKeys = null;
|
|
126
|
-
let referenceTypes = null;
|
|
127
|
-
function getReferenceData() {
|
|
128
|
-
if (!referenceKeys || !referenceTypes) {
|
|
129
|
-
const demo = funcListenCallbackBase(() => { });
|
|
130
|
-
referenceKeys = Object.keys(demo).sort();
|
|
131
|
-
referenceTypes = new Map();
|
|
132
|
-
for (const key of referenceKeys) {
|
|
133
|
-
referenceTypes.set(key, typeof demo[key]);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return { keys: referenceKeys, types: referenceTypes };
|
|
137
|
-
}
|
|
138
|
-
function isListenCallback(obj) {
|
|
139
|
-
if (obj == null || typeof obj !== "object")
|
|
140
|
-
return false;
|
|
141
|
-
const objKeys = Object.keys(obj).sort();
|
|
142
|
-
const { keys: refKeys, types: refTypes } = getReferenceData();
|
|
143
|
-
if (objKeys.length !== refKeys.length)
|
|
144
|
-
return false;
|
|
145
|
-
for (let i = 0; i < refKeys.length; i++) {
|
|
146
|
-
if (objKeys[i] !== refKeys[i])
|
|
147
|
-
return false;
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
148
7
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Listen3"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Listen3";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Listen3"), exports);
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
export type Listener<T extends any[]> = (...r: T) => void;
|
|
2
|
+
export type NormalizeTuple<T> = T extends any[] ? T : [T];
|
|
3
|
+
type key = string | symbol;
|
|
4
|
+
type cbClose = () => void;
|
|
5
|
+
declare const LISTEN_ON_BRAND: unique symbol;
|
|
6
|
+
export type ListenOn<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: {
|
|
7
|
+
cbClose?: cbClose;
|
|
8
|
+
key?: key;
|
|
9
|
+
}) => (() => void)) & {
|
|
10
|
+
readonly [LISTEN_ON_BRAND]: Z;
|
|
11
|
+
};
|
|
12
|
+
export type ListenOnCurrent<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: {
|
|
13
|
+
cbClose?: cbClose;
|
|
14
|
+
key?: key;
|
|
15
|
+
current?: ListenCurrent<Z>;
|
|
16
|
+
}) => (() => void)) & {
|
|
17
|
+
readonly [LISTEN_ON_BRAND]: Z;
|
|
18
|
+
};
|
|
19
|
+
export type ListenCurrentProvider<Z extends any[]> = () => Z | undefined;
|
|
20
|
+
export type ListenCurrent<Z extends any[]> = boolean | ListenCurrentProvider<Z>;
|
|
21
|
+
export type ListenCoreOptions<T = any> = {
|
|
22
|
+
fast?: boolean;
|
|
23
|
+
onRemove?: (k: key) => void;
|
|
24
|
+
event?: (type: 'add' | 'remove', count: number, api: ListenCoreApi<T>) => void;
|
|
25
|
+
};
|
|
26
|
+
export type ListenOptions<T> = {
|
|
27
|
+
event?: (type: 'add' | 'remove', count: number, api: ListenApi<T>) => void;
|
|
28
|
+
fast?: boolean;
|
|
29
|
+
addListenClose?: ListenApi<any>;
|
|
30
|
+
};
|
|
31
|
+
export type ListenStoreOptions<T> = ListenOptions<T> & {
|
|
32
|
+
current: ListenCurrentProvider<NormalizeTuple<T>>;
|
|
33
|
+
};
|
|
34
|
+
export declare function getListenByOn(fn: any): any;
|
|
35
|
+
export declare function isListenOn(fn: any): boolean;
|
|
36
|
+
export declare function funcListenCore<T>(options?: ListenCoreOptions<T>): {
|
|
37
|
+
func: Listener<NormalizeTuple<T>>;
|
|
38
|
+
has: (k: key) => boolean;
|
|
39
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
40
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
41
|
+
key?: key;
|
|
42
|
+
}) => () => void;
|
|
43
|
+
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
44
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
45
|
+
key?: key;
|
|
46
|
+
}) => () => void;
|
|
47
|
+
close: () => void;
|
|
48
|
+
count: () => number;
|
|
49
|
+
readonly getAllKeys: key[];
|
|
50
|
+
};
|
|
51
|
+
export type ListenCoreApi<T = any> = ReturnType<typeof funcListenCore<T>>;
|
|
52
|
+
export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), options?: ListenOptions<T>): {
|
|
53
|
+
func: Listener<NormalizeTuple<T>>;
|
|
54
|
+
isRun: () => boolean;
|
|
55
|
+
run: () => void;
|
|
56
|
+
close: () => void;
|
|
57
|
+
eventClose: (cb: cbClose) => () => void;
|
|
58
|
+
onClose: (cb: cbClose) => () => void;
|
|
59
|
+
removeEventClose: (cb: cbClose) => void;
|
|
60
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
61
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
62
|
+
cbClose?: cbClose;
|
|
63
|
+
key?: key;
|
|
64
|
+
}) => () => void;
|
|
65
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
66
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
67
|
+
key?: key;
|
|
68
|
+
}) => () => void;
|
|
69
|
+
count: () => number;
|
|
70
|
+
readonly getAllKeys: key[];
|
|
71
|
+
};
|
|
72
|
+
export type ListenApi<T = any> = ReturnType<typeof funcListenCallbackBase<T>>;
|
|
73
|
+
export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void))): {
|
|
74
|
+
func: Listener<NormalizeTuple<T>>;
|
|
75
|
+
isRun: () => boolean;
|
|
76
|
+
run: () => void;
|
|
77
|
+
close: () => void;
|
|
78
|
+
eventClose: (cb: cbClose) => () => void;
|
|
79
|
+
onClose: (cb: cbClose) => () => void;
|
|
80
|
+
removeEventClose: (cb: cbClose) => void;
|
|
81
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
82
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
83
|
+
cbClose?: cbClose;
|
|
84
|
+
key?: key;
|
|
85
|
+
}) => () => void;
|
|
86
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
87
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
88
|
+
key?: key;
|
|
89
|
+
}) => () => void;
|
|
90
|
+
count: () => number;
|
|
91
|
+
readonly getAllKeys: key[];
|
|
92
|
+
};
|
|
93
|
+
export declare const funcListenCallback: typeof funcListenCallbackBase;
|
|
94
|
+
export declare function UseListen<T>(data?: ListenOptions<T>): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
95
|
+
func: Listener<NormalizeTuple<T>>;
|
|
96
|
+
isRun: () => boolean;
|
|
97
|
+
run: () => void;
|
|
98
|
+
close: () => void;
|
|
99
|
+
eventClose: (cb: cbClose) => () => void;
|
|
100
|
+
onClose: (cb: cbClose) => () => void;
|
|
101
|
+
removeEventClose: (cb: cbClose) => void;
|
|
102
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
103
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
104
|
+
cbClose?: cbClose;
|
|
105
|
+
key?: key;
|
|
106
|
+
}) => () => void;
|
|
107
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
108
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
109
|
+
key?: key;
|
|
110
|
+
}) => () => void;
|
|
111
|
+
count: () => number;
|
|
112
|
+
readonly getAllKeys: key[];
|
|
113
|
+
}];
|
|
114
|
+
export declare function withStoreListen<T>(base: ListenApi<T>, currentProvider: ListenCurrentProvider<NormalizeTuple<T>>): {
|
|
115
|
+
on: ListenOnCurrent<NormalizeTuple<T>>;
|
|
116
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
117
|
+
cbClose?: cbClose;
|
|
118
|
+
key?: key;
|
|
119
|
+
current?: ListenCurrent<NormalizeTuple<T>>;
|
|
120
|
+
}) => () => void;
|
|
121
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
122
|
+
key?: key;
|
|
123
|
+
current?: ListenCurrent<NormalizeTuple<T>>;
|
|
124
|
+
}) => () => void;
|
|
125
|
+
getAllKeys: key[];
|
|
126
|
+
func: Listener<NormalizeTuple<T>>;
|
|
127
|
+
isRun: () => boolean;
|
|
128
|
+
run: () => void;
|
|
129
|
+
close: () => void;
|
|
130
|
+
eventClose: (cb: cbClose) => () => void;
|
|
131
|
+
onClose: (cb: cbClose) => () => void;
|
|
132
|
+
removeEventClose: (cb: cbClose) => void;
|
|
133
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
134
|
+
count: () => number;
|
|
135
|
+
};
|
|
136
|
+
export type ListenStoreApi<T> = ReturnType<typeof withStoreListen<T>>;
|
|
137
|
+
export declare function funcListenCallbackStore<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), options: ListenStoreOptions<T>): {
|
|
138
|
+
on: ListenOnCurrent<NormalizeTuple<T>>;
|
|
139
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
140
|
+
cbClose?: cbClose;
|
|
141
|
+
key?: key;
|
|
142
|
+
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
143
|
+
}) => () => void;
|
|
144
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
145
|
+
key?: key;
|
|
146
|
+
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
147
|
+
}) => () => void;
|
|
148
|
+
getAllKeys: key[];
|
|
149
|
+
func: Listener<NormalizeTuple<T>>;
|
|
150
|
+
isRun: () => boolean;
|
|
151
|
+
run: () => void;
|
|
152
|
+
close: () => void;
|
|
153
|
+
eventClose: (cb: cbClose) => () => void;
|
|
154
|
+
onClose: (cb: cbClose) => () => void;
|
|
155
|
+
removeEventClose: (cb: cbClose) => void;
|
|
156
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
157
|
+
count: () => number;
|
|
158
|
+
};
|
|
159
|
+
export declare function UseListenStore<T>(data: ListenStoreOptions<T>): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
160
|
+
on: ListenOnCurrent<NormalizeTuple<T>>;
|
|
161
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
162
|
+
cbClose?: cbClose;
|
|
163
|
+
key?: key;
|
|
164
|
+
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
165
|
+
}) => () => void;
|
|
166
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
167
|
+
key?: key;
|
|
168
|
+
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
169
|
+
}) => () => void;
|
|
170
|
+
getAllKeys: key[];
|
|
171
|
+
func: Listener<NormalizeTuple<T>>;
|
|
172
|
+
isRun: () => boolean;
|
|
173
|
+
run: () => void;
|
|
174
|
+
close: () => void;
|
|
175
|
+
eventClose: (cb: cbClose) => () => void;
|
|
176
|
+
onClose: (cb: cbClose) => () => void;
|
|
177
|
+
removeEventClose: (cb: cbClose) => void;
|
|
178
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
179
|
+
count: () => number;
|
|
180
|
+
}];
|
|
181
|
+
export declare function toListen2<T>(full: ListenApi<T>): {
|
|
182
|
+
on: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
183
|
+
key?: key;
|
|
184
|
+
}) => () => void;
|
|
185
|
+
close: () => void;
|
|
186
|
+
count: () => number;
|
|
187
|
+
};
|
|
188
|
+
export type Listen2<T> = ReturnType<typeof toListen2<T>>;
|
|
189
|
+
export declare function UseListen2<T>(data?: ListenOptions<T>): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
190
|
+
on: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
191
|
+
key?: key;
|
|
192
|
+
} | undefined) => () => void;
|
|
193
|
+
close: () => void;
|
|
194
|
+
count: () => number;
|
|
195
|
+
}];
|
|
196
|
+
export declare function isListenCallback(obj: any): obj is ListenApi;
|
|
197
|
+
export {};
|