feat: focus search bar on second tab press (#558)

This commit is contained in:
Fredrik Burmester
2025-02-22 13:09:17 +01:00
committed by GitHub
parent 5590c2f784
commit af2bd030e9
3 changed files with 59 additions and 2 deletions

26
utils/eventBus.ts Normal file
View File

@@ -0,0 +1,26 @@
type Listener<T = void> = (data?: T) => void;
class EventBus {
private listeners: Record<string, Listener<any>[]> = {};
on<T = void>(event: string, callback: Listener<T>): () => void {
if (!this.listeners[event]) {
this.listeners[event] = [];
}
this.listeners[event].push(callback);
return () => this.off(event, callback);
}
off<T = void>(event: string, callback: Listener<T>): void {
if (!this.listeners[event]) return;
this.listeners[event] = this.listeners[event].filter(
(fn) => fn !== callback
);
}
emit<T = void>(event: string, data?: T): void {
this.listeners[event]?.forEach((callback) => callback(data));
}
}
export const eventBus = new EventBus();