diff --git a/app/src/App.vue b/app/src/App.vue index 801ea07..ca96f89 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -17,9 +17,7 @@ const logout = () => { const isOnline = ref(navigator.onLine); onMounted(() => { - EventBus.on("logout", () => { - logout(); - }); + EventBus.on("logout", logout); window.addEventListener("online", () => isOnline.value = true); window.addEventListener("offline", () => isOnline.value = false); @@ -32,7 +30,7 @@ onMounted(() => { }); onBeforeUnmount(() => { - EventBus.remove("logout", null); + EventBus.remove("logout", logout); }) diff --git a/app/src/common/EventBus.ts b/app/src/common/EventBus.ts index ff070f2..d403416 100644 --- a/app/src/common/EventBus.ts +++ b/app/src/common/EventBus.ts @@ -1,13 +1,27 @@ -const eventBus = { - on(event: string, callback: EventListenerOrEventListenerObject) { - document.addEventListener(event, (e) => callback(e.detail)); - }, - dispatch(event: string, data: any) { - document.dispatchEvent(new CustomEvent(event, { detail: data })); - }, - remove(event: string, callback: EventListenerOrEventListenerObject) { - document.removeEventListener(event, callback); - }, -}; +// const eventBus = { +// on(event: string, callback: EventListenerOrEventListenerObject) { +// document.addEventListener(event, (e: CustomEvent) => callback(e.detail)); +// }, +// dispatch(event: string, data: any) { +// document.dispatchEvent(new CustomEvent(event, { detail: data })); +// }, +// remove(event: string, callback: EventListenerOrEventListenerObject) { +// document.removeEventListener(event, callback); +// }, +// }; -export default eventBus; +class EventBus { + on(type: string, listener: (event: T) => void, options?: boolean | AddEventListenerOptions): void { + document.addEventListener(type, listener as EventListener, options); + } + + dispatch(event: T): void { + document.dispatchEvent(event); + } + + remove(type: string, listener: (event: T) => void, options?: boolean | EventListenerOptions): void { + document.removeEventListener(type, listener as EventListener, options); + } +} + +export default new EventBus();