2022-04-16 18:25:42 +00:00
|
|
|
// one day it might be a good idea to replace all this with redux, but it'd take
|
|
|
|
// a lot of rewriting
|
2021-04-12 19:35:17 +00:00
|
|
|
export default class EventBus {
|
|
|
|
static on(event, callback) {
|
2021-04-21 18:35:33 +00:00
|
|
|
document.addEventListener(event, (e) => {
|
|
|
|
callback(e.detail);
|
|
|
|
});
|
2021-04-12 19:35:17 +00:00
|
|
|
}
|
2021-04-12 17:55:02 +00:00
|
|
|
|
2021-04-12 19:35:17 +00:00
|
|
|
static dispatch(event, data) {
|
2022-04-11 21:57:07 +00:00
|
|
|
document.dispatchEvent(
|
|
|
|
new CustomEvent(event, {
|
|
|
|
detail: data,
|
|
|
|
}),
|
|
|
|
);
|
2021-04-12 19:35:17 +00:00
|
|
|
}
|
2021-04-12 17:55:02 +00:00
|
|
|
|
2021-08-20 21:06:40 +00:00
|
|
|
static off(event, callback) {
|
2021-04-12 17:55:02 +00:00
|
|
|
document.removeEventListener(event, callback);
|
2021-04-12 19:35:17 +00:00
|
|
|
}
|
|
|
|
}
|