@stonyx/events 0.1.1-beta.36 → 0.1.1-beta.37
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/main.js +7 -4
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -39,6 +39,8 @@ class Events {
|
|
|
39
39
|
throw new Error('Callback must be a function');
|
|
40
40
|
}
|
|
41
41
|
const subscribers = this.events.get(event);
|
|
42
|
+
if (!subscribers)
|
|
43
|
+
throw new Error(`Event "${event}" subscribers not found in events Map`);
|
|
42
44
|
subscribers.add(callback);
|
|
43
45
|
// Return unsubscribe function
|
|
44
46
|
return () => this.unsubscribe(event, callback);
|
|
@@ -61,13 +63,16 @@ class Events {
|
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
65
|
const subscribers = this.events.get(event);
|
|
64
|
-
subscribers
|
|
66
|
+
if (subscribers)
|
|
67
|
+
subscribers.delete(callback);
|
|
65
68
|
}
|
|
66
69
|
async emit(event, ...args) {
|
|
67
70
|
if (!this.events.has(event)) {
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
70
73
|
const subscribers = this.events.get(event);
|
|
74
|
+
if (!subscribers)
|
|
75
|
+
return;
|
|
71
76
|
// Execute all handlers with error isolation
|
|
72
77
|
const promises = Array.from(subscribers).map(async (callback) => {
|
|
73
78
|
try {
|
|
@@ -80,9 +85,7 @@ class Events {
|
|
|
80
85
|
await Promise.all(promises);
|
|
81
86
|
}
|
|
82
87
|
clear(event) {
|
|
83
|
-
|
|
84
|
-
this.events.get(event).clear();
|
|
85
|
-
}
|
|
88
|
+
this.events.get(event)?.clear();
|
|
86
89
|
}
|
|
87
90
|
reset() {
|
|
88
91
|
this.events.clear();
|