@idlebox/common 1.3.1 → 1.3.2
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/docs/package-public.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export declare const bindThis: MethodDecorator;
|
|
|
99
99
|
export declare class CallbackList<Argument extends unknown[]> {
|
|
100
100
|
protected list: MyCallback<Argument>[];
|
|
101
101
|
protected running: boolean;
|
|
102
|
+
protected stop: boolean;
|
|
102
103
|
constructor();
|
|
103
104
|
count(): number;
|
|
104
105
|
reset(): void;
|
|
@@ -112,10 +113,10 @@ export declare class CallbackList<Argument extends unknown[]> {
|
|
|
112
113
|
*/
|
|
113
114
|
remove(item: MyCallback<Argument>): null | MyCallback<Argument>;
|
|
114
115
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @returns {boolean} true if one callback return true
|
|
116
|
+
* @returns {boolean} true if every callback called, false if stop in middle
|
|
117
117
|
*/
|
|
118
118
|
run(...argument: Argument): boolean;
|
|
119
|
+
stopRun(): void;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
/** @public */
|
|
@@ -644,7 +645,7 @@ export declare interface MyAsyncCallback<Argument extends unknown[]> {
|
|
|
644
645
|
|
|
645
646
|
export declare interface MyCallback<Argument extends unknown[]> {
|
|
646
647
|
displayName?: string;
|
|
647
|
-
(...param: Argument):
|
|
648
|
+
(...param: Argument): any;
|
|
648
649
|
}
|
|
649
650
|
|
|
650
651
|
export declare interface MyDelayCallback<Argument extends unknown[]> {
|
|
@@ -19,6 +19,12 @@ class CallbackList {
|
|
|
19
19
|
writable: true,
|
|
20
20
|
value: false
|
|
21
21
|
});
|
|
22
|
+
Object.defineProperty(this, "stop", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: false
|
|
27
|
+
});
|
|
22
28
|
this.run = this.run.bind(this);
|
|
23
29
|
}
|
|
24
30
|
count() {
|
|
@@ -57,18 +63,27 @@ class CallbackList {
|
|
|
57
63
|
return null;
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @returns {boolean} true if one callback return true
|
|
66
|
+
* @returns {boolean} true if every callback called, false if stop in middle
|
|
62
67
|
*/
|
|
63
68
|
run(...argument) {
|
|
69
|
+
if (this.running) {
|
|
70
|
+
throw new Error("can not run CallbackList in it's callback.");
|
|
71
|
+
}
|
|
72
|
+
this.stop = false;
|
|
64
73
|
this.running = true;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
for (const cb of this.list) {
|
|
75
|
+
if (this.stop)
|
|
76
|
+
break;
|
|
77
|
+
cb(...argument);
|
|
78
|
+
}
|
|
69
79
|
this.running = false;
|
|
80
|
+
const ret = !this.stop;
|
|
81
|
+
this.stop = false;
|
|
70
82
|
return ret;
|
|
71
83
|
}
|
|
84
|
+
stopRun() {
|
|
85
|
+
this.stop = true;
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
88
|
exports.CallbackList = CallbackList;
|
|
74
89
|
//# sourceMappingURL=callbackList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callbackList.js","sourceRoot":"","sources":["../../src/function/callbackList.ts"],"names":[],"mappings":";;;AAAA,yDAA8C;AAQ9C;;GAEG;AACH,MAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"callbackList.js","sourceRoot":"","sources":["../../src/function/callbackList.ts"],"names":[],"mappings":";;;AAAA,yDAA8C;AAQ9C;;GAEG;AACH,MAAa,YAAY;IAKxB;QAJA;;;;mBAAyC,EAAE;WAAC;QAC5C;;;;mBAA6B,KAAK;WAAC;QACnC;;;;mBAA0B,KAAK;WAAC;QAG/B,IAAI,CAAC,GAAG,GAAI,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAA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C;SAChB;QACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,OAAO;QACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAxED,oCAwEC"}
|
|
@@ -5,6 +5,7 @@ import { nameFunction } from "./functionName.js";
|
|
|
5
5
|
export class CallbackList {
|
|
6
6
|
list = [];
|
|
7
7
|
running = false;
|
|
8
|
+
stop = false;
|
|
8
9
|
constructor() {
|
|
9
10
|
this.run = this.run.bind(this);
|
|
10
11
|
}
|
|
@@ -44,17 +45,26 @@ export class CallbackList {
|
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @returns {boolean} true if one callback return true
|
|
48
|
+
* @returns {boolean} true if every callback called, false if stop in middle
|
|
49
49
|
*/
|
|
50
50
|
run(...argument) {
|
|
51
|
+
if (this.running) {
|
|
52
|
+
throw new Error("can not run CallbackList in it's callback.");
|
|
53
|
+
}
|
|
54
|
+
this.stop = false;
|
|
51
55
|
this.running = true;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
for (const cb of this.list) {
|
|
57
|
+
if (this.stop)
|
|
58
|
+
break;
|
|
59
|
+
cb(...argument);
|
|
60
|
+
}
|
|
56
61
|
this.running = false;
|
|
62
|
+
const ret = !this.stop;
|
|
63
|
+
this.stop = false;
|
|
57
64
|
return ret;
|
|
58
65
|
}
|
|
66
|
+
stopRun() {
|
|
67
|
+
this.stop = true;
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
//# sourceMappingURL=callbackList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callbackList.js","sourceRoot":"","sources":["../../src/function/callbackList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,0BAAuB;AAQ9C;;GAEG;AACH,MAAM,OAAO,YAAY;IACd,IAAI,GAA2B,EAAE,CAAC;IAClC,OAAO,GAAY,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"callbackList.js","sourceRoot":"","sources":["../../src/function/callbackList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,0BAAuB;AAQ9C;;GAEG;AACH,MAAM,OAAO,YAAY;IACd,IAAI,GAA2B,EAAE,CAAC;IAClC,OAAO,GAAY,KAAK,CAAC;IACzB,IAAI,GAAY,KAAK,CAAC;IAEhC;QACC,IAAI,CAAC,GAAG,GAAI,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACpD;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,IAA0B,EAAE,IAAa;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC3D;QACD,IAAI,IAAI,EAAE;YACT,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACzB;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAA0B;QAChC,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;SAC9D;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAG,QAAkB;QACxB,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;SAC9D;QACD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAElB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE;YAC3B,IAAI,IAAI,CAAC,IAAI;gBAAE,MAAM;YACrB,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC;SAChB;QACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,OAAO;QACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { nameFunction } from './functionName';
|
|
|
3
3
|
export interface MyCallback<Argument extends unknown[]> {
|
|
4
4
|
displayName?: string;
|
|
5
5
|
|
|
6
|
-
(...param: Argument):
|
|
6
|
+
(...param: Argument): any;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -12,6 +12,7 @@ export interface MyCallback<Argument extends unknown[]> {
|
|
|
12
12
|
export class CallbackList<Argument extends unknown[]> {
|
|
13
13
|
protected list: MyCallback<Argument>[] = [];
|
|
14
14
|
protected running: boolean = false;
|
|
15
|
+
protected stop: boolean = false;
|
|
15
16
|
|
|
16
17
|
constructor() {
|
|
17
18
|
this.run = (this.run as any).bind(this);
|
|
@@ -57,16 +58,27 @@ export class CallbackList<Argument extends unknown[]> {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @returns {boolean} true if one callback return true
|
|
61
|
+
* @returns {boolean} true if every callback called, false if stop in middle
|
|
62
62
|
*/
|
|
63
63
|
run(...argument: Argument): boolean {
|
|
64
|
+
if (this.running) {
|
|
65
|
+
throw new Error("can not run CallbackList in it's callback.");
|
|
66
|
+
}
|
|
67
|
+
this.stop = false;
|
|
68
|
+
|
|
64
69
|
this.running = true;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
70
|
+
for (const cb of this.list) {
|
|
71
|
+
if (this.stop) break;
|
|
72
|
+
cb(...argument);
|
|
73
|
+
}
|
|
69
74
|
this.running = false;
|
|
75
|
+
|
|
76
|
+
const ret = !this.stop;
|
|
77
|
+
this.stop = false;
|
|
70
78
|
return ret;
|
|
71
79
|
}
|
|
80
|
+
|
|
81
|
+
stopRun() {
|
|
82
|
+
this.stop = true;
|
|
83
|
+
}
|
|
72
84
|
}
|