Skip to content

Instantly share code, notes, and snippets.

View denisputnov's full-sized avatar
🎯
Focusing

Denis Putnov denisputnov

🎯
Focusing
View GitHub Profile
import {useEffect} from 'react';
type EventKey = string;
type EventHandler<T = any> = (payload: T) => void;
type EventMap = Record<EventKey, EventHandler>;
type Bus<E> = Record<keyof E, E[keyof E][]>;
interface EventBus<T extends EventMap> {
on<Key extends keyof T>(key: Key, handler: T[Key]): () => void;
off<Key extends keyof T>(key: Key, handler: T[Key]): void;