From 884e2c700e4c551491983491d5497a81ea92db52 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:26:38 -0500 Subject: [PATCH] remove old event bus code --- frontend/composables/use-events.ts | 38 ------------------------------ 1 file changed, 38 deletions(-) delete mode 100644 frontend/composables/use-events.ts diff --git a/frontend/composables/use-events.ts b/frontend/composables/use-events.ts deleted file mode 100644 index 92c8cdd..0000000 --- a/frontend/composables/use-events.ts +++ /dev/null @@ -1,38 +0,0 @@ -export enum EventTypes { - // ClearStores event is used to inform the stores that _all_ the data they are using - // is now out of date and they should refresh - This is used when the user makes large - // changes to the data such as bulk actions or importing a CSV file - InvalidStores, -} - -export type EventFn = () => void; - -export interface IEventBus { - on(event: EventTypes, fn: EventFn, key: string): void; - off(event: EventTypes, key: string): void; - emit(event: EventTypes): void; -} - -class EventBus implements IEventBus { - private listeners: Record> = { - [EventTypes.InvalidStores]: {}, - }; - - on(event: EventTypes, fn: EventFn, key: string): void { - this.listeners[event][key] = fn; - } - - off(event: EventTypes, key: string): void { - delete this.listeners[event][key]; - } - - emit(event: EventTypes): void { - Object.values(this.listeners[event]).forEach(fn => fn()); - } -} - -const bus = new EventBus(); - -export function useEventBus(): IEventBus { - return bus; -}