1
0
Fork 1
mirror of https://github.com/hay-kot/homebox.git synced 2024-12-22 14:56:31 +00:00
homebox/frontend/composables/use-events.ts
Hayden bd06fdafaf
feat: enhanced search functions ()
* make login case insensitive

* expand query to support by Field and By AID search

* type generation

* new API callers

* rework search to support field queries

* improve unnecessary data fetches

* clear stores on logout

* change verbage

* add labels
2023-02-05 12:12:54 -09:00

38 lines
1,023 B
TypeScript

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, Record<string, EventFn>> = {
[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;
}