@leyyo/common 1.3.19 → 1.3.20
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/dist/base/index.types.d.ts +67 -0
- package/dist/base/index.types.js +32 -0
- package/dist/base/leyyo.d.ts +3 -0
- package/dist/base/leyyo.js +18 -7
- package/dist/class/index.types.d.ts +20 -0
- package/dist/class/list.d.ts +6 -0
- package/dist/class/list.js +6 -0
- package/dist/class/logger.instance.d.ts +5 -0
- package/dist/class/logger.instance.js +13 -0
- package/dist/common/deploy.common.d.ts +16 -0
- package/dist/common/deploy.common.js +17 -0
- package/dist/common/enum.pool.d.ts +10 -0
- package/dist/common/enum.pool.js +14 -0
- package/dist/common/error.common.d.ts +30 -0
- package/dist/common/error.common.js +40 -0
- package/dist/common/error.pool.d.ts +9 -0
- package/dist/common/error.pool.js +10 -0
- package/dist/common/event.common.d.ts +8 -0
- package/dist/common/event.common.js +16 -3
- package/dist/common/index.types.d.ts +432 -0
- package/dist/common/index.types.js +1 -0
- package/dist/common/inert.d.ts +48 -0
- package/dist/common/inert.js +29 -0
- package/dist/common/lifecycle.common.d.ts +14 -0
- package/dist/common/lifecycle.common.js +16 -0
- package/dist/common/literal.pool.d.ts +11 -0
- package/dist/common/literal.pool.js +15 -0
- package/dist/common/log.common.d.ts +54 -0
- package/dist/common/log.common.js +96 -6
- package/dist/common/repo.common.d.ts +188 -0
- package/dist/common/repo.common.js +211 -0
- package/dist/const/index.d.ts +6 -0
- package/dist/const/index.js +7 -0
- package/dist/enum/log-level.d.ts +3 -0
- package/dist/error/caused.error.d.ts +10 -0
- package/dist/error/caused.error.js +10 -0
- package/dist/error/developer.error.d.ts +8 -0
- package/dist/error/developer.error.js +10 -0
- package/dist/error/http.error.d.ts +13 -0
- package/dist/error/http.error.js +7 -0
- package/dist/error/index.types.d.ts +149 -0
- package/dist/error/invalid-value.error.d.ts +3 -0
- package/dist/error/invalid-value.error.js +3 -0
- package/dist/error/leyyo.error.d.ts +33 -0
- package/dist/error/leyyo.error.js +36 -0
- package/dist/error/multiple.error.d.ts +6 -0
- package/dist/error/multiple.error.js +7 -0
- package/dist/function/define-loader.d.ts +6 -0
- package/dist/function/define-loader.js +6 -0
- package/dist/function/delay.d.ts +8 -0
- package/dist/function/delay.js +9 -0
- package/dist/function/delete-prop.d.ts +21 -0
- package/dist/function/delete-prop.js +22 -0
- package/dist/function/empty-fn.d.ts +6 -0
- package/dist/function/empty-fn.js +7 -0
- package/dist/function/extended-type.d.ts +6 -0
- package/dist/function/extended-type.js +7 -0
- package/dist/function/get-fqn.d.ts +6 -0
- package/dist/function/get-fqn.js +7 -0
- package/dist/function/get-prop.d.ts +21 -0
- package/dist/function/get-prop.js +21 -0
- package/dist/function/get-stat.d.ts +20 -0
- package/dist/function/has-fqn.d.ts +6 -0
- package/dist/function/has-fqn.js +7 -0
- package/dist/function/is-class.d.ts +6 -0
- package/dist/function/is-class.js +18 -0
- package/dist/function/is-empty.d.ts +11 -0
- package/dist/function/is-empty.js +11 -0
- package/dist/function/is-filled-arr.d.ts +9 -0
- package/dist/function/is-filled-arr.js +9 -0
- package/dist/function/is-filled-obj.d.ts +9 -0
- package/dist/function/is-filled-obj.js +9 -0
- package/dist/function/is-obj.d.ts +8 -0
- package/dist/function/is-obj.js +8 -0
- package/dist/function/is-test.d.ts +8 -0
- package/dist/function/is-test.js +14 -0
- package/dist/function/is-text.d.ts +10 -0
- package/dist/function/is-text.js +10 -0
- package/dist/function/jitter-interval.d.ts +9 -0
- package/dist/function/jitter-interval.js +16 -0
- package/dist/function/load-config.d.ts +19 -0
- package/dist/function/load-config.js +52 -1
- package/dist/function/on-fqn-set.js +1 -0
- package/dist/function/one-or-more.d.ts +6 -0
- package/dist/function/one-or-more.js +7 -0
- package/dist/function/opt-add.d.ts +8 -0
- package/dist/function/opt-add.js +8 -0
- package/dist/function/opt-append.d.ts +7 -0
- package/dist/function/opt-append.js +7 -0
- package/dist/function/opt-check.d.ts +6 -0
- package/dist/function/opt-check.js +7 -0
- package/dist/function/opt-clone.d.ts +6 -0
- package/dist/function/opt-clone.js +7 -0
- package/dist/function/opt-field.d.ts +8 -0
- package/dist/function/opt-field.js +8 -0
- package/dist/function/opt-fn.d.ts +6 -0
- package/dist/function/opt-fn.js +7 -0
- package/dist/function/random-test-no.d.ts +5 -0
- package/dist/function/random-test-no.js +5 -0
- package/dist/function/remove-fqn.d.ts +8 -0
- package/dist/function/remove-fqn.js +11 -1
- package/dist/function/run-exporter.d.ts +5 -0
- package/dist/function/run-exporter.js +14 -0
- package/dist/function/secure-json.d.ts +35 -0
- package/dist/function/secure-json.js +44 -0
- package/dist/function/set-anonymous-fqn.js +2 -0
- package/dist/function/set-fqn.d.ts +7 -0
- package/dist/function/set-fqn.js +8 -0
- package/dist/function/set-prop.d.ts +24 -0
- package/dist/function/set-prop.js +24 -0
- package/dist/function/stamp-loader.d.ts +6 -0
- package/dist/function/stamp-loader.js +6 -0
- package/dist/function/test-case.d.ts +7 -0
- package/dist/function/test-case.js +7 -0
- package/dist/function/test-name.d.ts +7 -0
- package/dist/function/test-name.js +7 -0
- package/dist/function/trigger-fqn.js +1 -0
- package/dist/index.foretell.js +3 -0
- package/dist/index.js +1 -0
- package/dist/index.loader.js +8 -1
- package/dist/sys/leyyo-storage.d.ts +7 -0
- package/dist/sys/leyyo-storage.js +23 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import * as stackTraceParser from "stacktrace-parser";
|
|
|
3
3
|
import { FQN } from "../internal.js";
|
|
4
4
|
import { KEY_ERROR_DEFAULT_MESSAGE, KEY_ERROR_EMIT, KEY_ERROR_EMITTED, KEY_ERROR_I18N, KEY_ERROR_RAISED, VAL_ERROR_UNKNOWN_MESSAGE, VAL_ERROR_UNKNOWN_NAME, } from "../const/index.js";
|
|
5
5
|
const where = `${FQN}.ErrorCommon`;
|
|
6
|
+
// noinspection JSUnusedGlobalSymbols
|
|
6
7
|
export class ErrorCommon {
|
|
7
8
|
leyyo;
|
|
8
9
|
_knownPackages;
|
|
@@ -11,6 +12,16 @@ export class ErrorCommon {
|
|
|
11
12
|
constructor(leyyo) {
|
|
12
13
|
this.leyyo = leyyo;
|
|
13
14
|
}
|
|
15
|
+
// region private
|
|
16
|
+
/**
|
|
17
|
+
* Transform error as a bare object
|
|
18
|
+
*
|
|
19
|
+
* @param {Error} err - error instance
|
|
20
|
+
* @param {Opt} existing - existing parameters
|
|
21
|
+
* @param {boolean} ignoreNameMessage - ignore name & message?
|
|
22
|
+
* @param {WeakSet} weakSet - weak set to prevent duplicates
|
|
23
|
+
* @return {Opt?} - bare error object
|
|
24
|
+
* */
|
|
14
25
|
_toErrorJson(err, existing, ignoreNameMessage, weakSet) {
|
|
15
26
|
if (!(err instanceof Error)) {
|
|
16
27
|
return undefined;
|
|
@@ -67,6 +78,12 @@ export class ErrorCommon {
|
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Build error info part as `<part1/part2>`
|
|
83
|
+
*
|
|
84
|
+
* @param {Array<string|number>} parts - parts for info
|
|
85
|
+
* @return {string}
|
|
86
|
+
* */
|
|
70
87
|
_buildTextParts(parts) {
|
|
71
88
|
parts = parts
|
|
72
89
|
.map((p) => {
|
|
@@ -84,6 +101,9 @@ export class ErrorCommon {
|
|
|
84
101
|
.filter(Boolean);
|
|
85
102
|
return parts.length > 0 ? "<" + parts.join("/") + "> " : "";
|
|
86
103
|
}
|
|
104
|
+
// endregion private
|
|
105
|
+
// region public
|
|
106
|
+
/** @inheritDoc */
|
|
87
107
|
setConfigItem(clazz, conf) {
|
|
88
108
|
if (!isClass(clazz)) {
|
|
89
109
|
throw new this.leyyo.developerError("Invalid package name", testCase(FQN, 230), where);
|
|
@@ -101,6 +121,7 @@ export class ErrorCommon {
|
|
|
101
121
|
setSymbol(clazz, KEY_ERROR_I18N, conf.i18n);
|
|
102
122
|
}
|
|
103
123
|
}
|
|
124
|
+
/** @inheritDoc */
|
|
104
125
|
getConfigItem(clazz) {
|
|
105
126
|
return {
|
|
106
127
|
message: getSymbol(clazz, KEY_ERROR_DEFAULT_MESSAGE),
|
|
@@ -108,20 +129,25 @@ export class ErrorCommon {
|
|
|
108
129
|
i18n: getSymbol(clazz, KEY_ERROR_I18N),
|
|
109
130
|
};
|
|
110
131
|
}
|
|
132
|
+
/** @inheritDoc */
|
|
111
133
|
emit(err) {
|
|
112
134
|
if (!(err instanceof Error)) {
|
|
113
135
|
return;
|
|
114
136
|
}
|
|
137
|
+
// already emitted
|
|
115
138
|
if (getSymbol(err, KEY_ERROR_EMITTED)) {
|
|
116
139
|
return;
|
|
117
140
|
}
|
|
118
141
|
const clazz = err.constructor;
|
|
142
|
+
// error does not support to emit
|
|
119
143
|
if (!getSymbol(clazz, KEY_ERROR_EMIT)) {
|
|
120
144
|
return;
|
|
121
145
|
}
|
|
146
|
+
// prevent duplicated emits
|
|
122
147
|
setSymbol(err, KEY_ERROR_EMITTED, true);
|
|
123
148
|
this.leyyo.eventCommon.emit("error:emit", err);
|
|
124
149
|
}
|
|
150
|
+
/** @inheritDoc */
|
|
125
151
|
buildStack(source, force) {
|
|
126
152
|
const err = source;
|
|
127
153
|
if (!force && Array.isArray(err.stackTrace)) {
|
|
@@ -188,14 +214,18 @@ export class ErrorCommon {
|
|
|
188
214
|
}
|
|
189
215
|
}
|
|
190
216
|
catch (e) {
|
|
217
|
+
// none
|
|
191
218
|
}
|
|
192
219
|
}
|
|
220
|
+
/** @inheritDoc */
|
|
193
221
|
toJsonBasic(err, existing) {
|
|
194
222
|
return this._toErrorJson(err, existing, true, new WeakSet());
|
|
195
223
|
}
|
|
224
|
+
/** @inheritDoc */
|
|
196
225
|
toJsonFull(err, existing) {
|
|
197
226
|
return this._toErrorJson(err, existing, false, new WeakSet());
|
|
198
227
|
}
|
|
228
|
+
/** @inheritDoc */
|
|
199
229
|
cast(e, params) {
|
|
200
230
|
if (!(e instanceof Error)) {
|
|
201
231
|
return new this.leyyo.leyyoError(secureJson(e));
|
|
@@ -208,6 +238,7 @@ export class ErrorCommon {
|
|
|
208
238
|
err.causedBy = e;
|
|
209
239
|
return err;
|
|
210
240
|
}
|
|
241
|
+
/** @inheritDoc */
|
|
211
242
|
forcedCast(clazz, e, params) {
|
|
212
243
|
if (!(e instanceof Error)) {
|
|
213
244
|
return new this.leyyo.leyyoError(secureJson(e));
|
|
@@ -223,6 +254,7 @@ export class ErrorCommon {
|
|
|
223
254
|
err.causedBy = e;
|
|
224
255
|
return err;
|
|
225
256
|
}
|
|
257
|
+
/** @inheritDoc */
|
|
226
258
|
addKnownPackage(packageName, shortName) {
|
|
227
259
|
if (!isText(packageName)) {
|
|
228
260
|
throw new this.leyyo.developerError("Invalid package name", testCase(FQN, 230), where);
|
|
@@ -238,6 +270,7 @@ export class ErrorCommon {
|
|
|
238
270
|
}
|
|
239
271
|
this._knownPackages.set(packageName, shortName);
|
|
240
272
|
}
|
|
273
|
+
/** @inheritDoc */
|
|
241
274
|
bareObj(err) {
|
|
242
275
|
if (err instanceof Error) {
|
|
243
276
|
return {
|
|
@@ -250,6 +283,7 @@ export class ErrorCommon {
|
|
|
250
283
|
message: VAL_ERROR_UNKNOWN_MESSAGE,
|
|
251
284
|
};
|
|
252
285
|
}
|
|
286
|
+
/** @inheritDoc */
|
|
253
287
|
text(err, ...parts) {
|
|
254
288
|
const info = parts.length > 0 ? this._buildTextParts(parts) : "";
|
|
255
289
|
if (err instanceof Error) {
|
|
@@ -257,6 +291,7 @@ export class ErrorCommon {
|
|
|
257
291
|
}
|
|
258
292
|
return `${info}[err:${VAL_ERROR_UNKNOWN_NAME}] => ^/${VAL_ERROR_UNKNOWN_MESSAGE}/$`;
|
|
259
293
|
}
|
|
294
|
+
/** @inheritDoc */
|
|
260
295
|
addStat(p1) {
|
|
261
296
|
let num = -1;
|
|
262
297
|
try {
|
|
@@ -288,9 +323,11 @@ export class ErrorCommon {
|
|
|
288
323
|
this._stats.set(clazz, num);
|
|
289
324
|
}
|
|
290
325
|
catch (e) {
|
|
326
|
+
// nothing
|
|
291
327
|
}
|
|
292
328
|
return num;
|
|
293
329
|
}
|
|
330
|
+
/** @inheritDoc */
|
|
294
331
|
getStat(p1) {
|
|
295
332
|
try {
|
|
296
333
|
let clazz;
|
|
@@ -309,15 +346,18 @@ export class ErrorCommon {
|
|
|
309
346
|
return this._stats.get(clazz) ?? 0;
|
|
310
347
|
}
|
|
311
348
|
catch (e) {
|
|
349
|
+
// nothing
|
|
312
350
|
}
|
|
313
351
|
return 0;
|
|
314
352
|
}
|
|
353
|
+
/** @inheritDoc */
|
|
315
354
|
clearStats() {
|
|
316
355
|
if (!this._stats) {
|
|
317
356
|
return;
|
|
318
357
|
}
|
|
319
358
|
this._stats.clear();
|
|
320
359
|
}
|
|
360
|
+
/** @inheritDoc */
|
|
321
361
|
listStats() {
|
|
322
362
|
if (!this._stats) {
|
|
323
363
|
return {};
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { Inert } from "./inert.js";
|
|
2
2
|
import { ErrorPoolItem, ErrorPoolLike, ErrorPoolOpt } from "./index.types.js";
|
|
3
3
|
import { ClassLike, LeyyoLike } from "../base/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Error pool for call with name and lazy loading
|
|
6
|
+
* */
|
|
4
7
|
export declare class ErrorPool extends Inert<ErrorPoolItem, ClassLike, ErrorPoolOpt> implements ErrorPoolLike {
|
|
5
8
|
protected leyyo: LeyyoLike;
|
|
6
9
|
constructor(leyyo: LeyyoLike);
|
|
10
|
+
/** @inheritDoc */
|
|
7
11
|
protected _getName(target: ClassLike): string;
|
|
12
|
+
/** @inheritDoc */
|
|
8
13
|
protected _nextLoad(_item: ErrorPoolItem): Promise<void>;
|
|
14
|
+
/** @inheritDoc */
|
|
9
15
|
protected _setName(target: ClassLike, _name: string): string;
|
|
16
|
+
/** @inheritDoc */
|
|
10
17
|
protected _afterTargetFound(item: ErrorPoolItem): void;
|
|
18
|
+
/** @inheritDoc */
|
|
11
19
|
protected _validate(target: ClassLike): boolean;
|
|
20
|
+
/** @inheritDoc */
|
|
12
21
|
define(fqn: string, target: ClassLike, opt?: Omit<ErrorPoolOpt, "name" | "target" | "lazyTarget" | "fqn">): void;
|
|
13
22
|
}
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { Inert } from "./inert.js";
|
|
2
2
|
import { isClass } from "../function/index.js";
|
|
3
|
+
// noinspection JSUnusedGlobalSymbols
|
|
4
|
+
/**
|
|
5
|
+
* Error pool for call with name and lazy loading
|
|
6
|
+
* */
|
|
3
7
|
export class ErrorPool extends Inert {
|
|
4
8
|
leyyo;
|
|
5
9
|
constructor(leyyo) {
|
|
6
10
|
super(leyyo, "error", { anonymousName: "Error" });
|
|
7
11
|
this.leyyo = leyyo;
|
|
8
12
|
}
|
|
13
|
+
/** @inheritDoc */
|
|
9
14
|
_getName(target) {
|
|
10
15
|
return target?.name;
|
|
11
16
|
}
|
|
17
|
+
/** @inheritDoc */
|
|
12
18
|
async _nextLoad(_item) { }
|
|
19
|
+
/** @inheritDoc */
|
|
13
20
|
_setName(target, _name) {
|
|
14
21
|
return target?.name;
|
|
15
22
|
}
|
|
23
|
+
/** @inheritDoc */
|
|
16
24
|
_afterTargetFound(item) {
|
|
17
25
|
if (item.lazyTarget) {
|
|
18
26
|
delete item.lazyTarget;
|
|
@@ -23,9 +31,11 @@ export class ErrorPool extends Inert {
|
|
|
23
31
|
i18n: item.i18n,
|
|
24
32
|
});
|
|
25
33
|
}
|
|
34
|
+
/** @inheritDoc */
|
|
26
35
|
_validate(target) {
|
|
27
36
|
return isClass(target);
|
|
28
37
|
}
|
|
38
|
+
/** @inheritDoc */
|
|
29
39
|
define(fqn, target, opt) {
|
|
30
40
|
this.register({ ...(opt ?? {}), fqn, target });
|
|
31
41
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { EventCommonLike, EventType } from "./index.types.js";
|
|
2
2
|
import { Fnc, LeyyoLike } from "../base/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Event common interface
|
|
5
|
+
* */
|
|
3
6
|
export declare class EventCommon<T extends string> implements EventCommonLike<T> {
|
|
4
7
|
private leyyo;
|
|
5
8
|
private readonly _emitter;
|
|
@@ -8,9 +11,14 @@ export declare class EventCommon<T extends string> implements EventCommonLike<T>
|
|
|
8
11
|
private readonly _removedEvents;
|
|
9
12
|
private readonly _deactivatedEvents;
|
|
10
13
|
constructor(leyyo: LeyyoLike);
|
|
14
|
+
/** @inheritDoc */
|
|
11
15
|
fork<F extends string>(): EventCommonLike<T | F>;
|
|
16
|
+
/** @inheritDoc */
|
|
12
17
|
emit(name: T, ...values: Array<unknown>): boolean;
|
|
18
|
+
/** @inheritDoc */
|
|
13
19
|
listen<T extends string = string>(name: EventType | T, callback: Fnc): void;
|
|
20
|
+
/** @inheritDoc */
|
|
14
21
|
deactivate(name: string): boolean;
|
|
22
|
+
/** @inheritDoc */
|
|
15
23
|
activate(name: string): boolean;
|
|
16
24
|
}
|
|
@@ -2,12 +2,16 @@ import { FQN } from "../internal.js";
|
|
|
2
2
|
import { isText, testCase } from "../function/index.js";
|
|
3
3
|
import EventEmitter from "node:events";
|
|
4
4
|
const where = `${FQN}.EventCommon`;
|
|
5
|
+
// noinspection JSUnusedGlobalSymbols
|
|
6
|
+
/**
|
|
7
|
+
* Event common interface
|
|
8
|
+
* */
|
|
5
9
|
export class EventCommon {
|
|
6
10
|
leyyo;
|
|
7
11
|
_emitter = new EventEmitter();
|
|
8
12
|
_listenedEvents;
|
|
9
13
|
_waitingEvents;
|
|
10
|
-
_removedEvents;
|
|
14
|
+
_removedEvents; // stored, emitted
|
|
11
15
|
_deactivatedEvents;
|
|
12
16
|
constructor(leyyo) {
|
|
13
17
|
this.leyyo = leyyo;
|
|
@@ -16,14 +20,17 @@ export class EventCommon {
|
|
|
16
20
|
this._removedEvents = this.leyyo.repoCommon.newMap(`${where}.removedEvents`);
|
|
17
21
|
this._deactivatedEvents = this.leyyo.repoCommon.newSet(`${where}.deactivatedEvents`);
|
|
18
22
|
}
|
|
23
|
+
/** @inheritDoc */
|
|
19
24
|
fork() {
|
|
20
25
|
return this;
|
|
21
26
|
}
|
|
27
|
+
/** @inheritDoc */
|
|
22
28
|
emit(name, ...values) {
|
|
23
29
|
if (!isText(name)) {
|
|
24
30
|
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 130), where);
|
|
25
31
|
}
|
|
26
32
|
if (!this._emitter.emit(name, ...values)) {
|
|
33
|
+
// It is deactivated, no collect it anymore
|
|
27
34
|
if (this._deactivatedEvents.has(name)) {
|
|
28
35
|
return true;
|
|
29
36
|
}
|
|
@@ -44,20 +51,22 @@ export class EventCommon {
|
|
|
44
51
|
this._removedEvents.set(name, parts);
|
|
45
52
|
}
|
|
46
53
|
else if (parts[0] >= 10_000) {
|
|
54
|
+
// there are too many events, and there is no any listener, close it
|
|
47
55
|
if (parts[1] > 50_000) {
|
|
48
56
|
this.deactivate(name);
|
|
49
57
|
return false;
|
|
50
58
|
}
|
|
59
|
+
// clear half of it
|
|
51
60
|
parts[0] = 5_000;
|
|
52
61
|
item.splice(0, 5_000);
|
|
53
|
-
parts[1]++;
|
|
62
|
+
parts[1]++; // increment emitted
|
|
54
63
|
this.leyyo.logger.warn(`Removed all messages. name: ${name}, times: ${parts[1]}`, {
|
|
55
64
|
where,
|
|
56
65
|
eventName: name,
|
|
57
66
|
});
|
|
58
67
|
}
|
|
59
68
|
else {
|
|
60
|
-
parts[1]++;
|
|
69
|
+
parts[1]++; // increment emitted
|
|
61
70
|
item.shift();
|
|
62
71
|
}
|
|
63
72
|
}
|
|
@@ -66,6 +75,7 @@ export class EventCommon {
|
|
|
66
75
|
}
|
|
67
76
|
return true;
|
|
68
77
|
}
|
|
78
|
+
/** @inheritDoc */
|
|
69
79
|
listen(name, callback) {
|
|
70
80
|
if (!isText(name)) {
|
|
71
81
|
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 130), where);
|
|
@@ -78,6 +88,7 @@ export class EventCommon {
|
|
|
78
88
|
this._emitter.removeAllListeners(name);
|
|
79
89
|
}
|
|
80
90
|
this._emitter.on(name, callback);
|
|
91
|
+
// if there is a listener, event will be activated automatically
|
|
81
92
|
this.activate(name);
|
|
82
93
|
this._listenedEvents.set(name, callback);
|
|
83
94
|
if (!exists) {
|
|
@@ -89,6 +100,7 @@ export class EventCommon {
|
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
}
|
|
103
|
+
/** @inheritDoc */
|
|
92
104
|
deactivate(name) {
|
|
93
105
|
if (!isText(name)) {
|
|
94
106
|
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 132), where);
|
|
@@ -109,6 +121,7 @@ export class EventCommon {
|
|
|
109
121
|
this._deactivatedEvents.add(name);
|
|
110
122
|
return true;
|
|
111
123
|
}
|
|
124
|
+
/** @inheritDoc */
|
|
112
125
|
activate(name) {
|
|
113
126
|
if (!isText(name)) {
|
|
114
127
|
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 133), where);
|