core: do not unsub all once events on publish

this was a stupid bug where publishing any type of event would
unsubscribe all events that had once set to true.
This commit is contained in:
Abdullah Atta
2023-02-28 12:09:50 +05:00
committed by Abdullah Atta
parent 4c541f3995
commit e53cc648f0

View File

@@ -53,16 +53,20 @@ class EventManager {
publish(name, ...args) {
this._registry.forEach((props, handler) => {
if (props.name === name) handler(...args);
if (props.once) this._registry.delete(handler);
if (props.name === name) {
handler(...args);
if (props.once) this._registry.delete(handler);
}
});
}
async publishWithResult(name, ...args) {
const handlers = [];
this._registry.forEach((props, handler) => {
if (props.name === name) handlers.push(handler);
if (props.once) this._registry.delete(handler);
if (props.name === name) {
handlers.push(handler);
if (props.once) this._registry.delete(handler);
}
});
if (handlers.length <= 0) return true;