mirror of
https://github.com/thelounge/thelounge
synced 2024-11-25 13:30:21 +00:00
Fix eventbus
This commit is contained in:
parent
8978be2fd7
commit
16646e1586
1 changed files with 12 additions and 4 deletions
|
@ -9,9 +9,9 @@ class EventBus {
|
|||
*/
|
||||
on(type, handler) {
|
||||
if (events.has(type)) {
|
||||
events[type].push(handler);
|
||||
events.get(type).push(handler);
|
||||
} else {
|
||||
events[type] = [handler];
|
||||
events.set(type, [handler]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,10 @@ class EventBus {
|
|||
*/
|
||||
off(type, handler) {
|
||||
if (events.has(type)) {
|
||||
events[type] = events[type].filter((item) => item !== handler);
|
||||
events.set(
|
||||
type,
|
||||
events.get(type).filter((item) => item !== handler)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +38,12 @@ class EventBus {
|
|||
*/
|
||||
emit(type, evt) {
|
||||
if (events.has(type)) {
|
||||
events[type].slice().map((handler) => handler(evt));
|
||||
events
|
||||
.get(type)
|
||||
.slice()
|
||||
.map((handler) => {
|
||||
handler(evt);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue