This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |