Skip to content

Instantly share code, notes, and snippets.

View SiddharthaChowdhury's full-sized avatar
🌄
Journey

Austin4Silvers SiddharthaChowdhury

🌄
Journey
View GitHub Profile
interface IKeyEventsListeners {
keyup: { [componentId: string]: (event: KeyboardEvent) => void };
keydown: { [componentId: string]: (event: KeyboardEvent) => void };
}
export interface IKeySubscription {
unsubscribe: () => void;
}
const keyListener = (<T extends keyof IKeyEventsListeners>() => {
@SiddharthaChowdhury
SiddharthaChowdhury / Pub-sub.ts
Last active July 19, 2024 11:39
Example Pub-Sub class typescript
type TEvent = 'player-icu';
type EventCallback<T> = (data: T) => void;
class EventPublisher {
// Subscription Record<EventName, Record<SubscriberId, callback>>
private subscriptions: Record<
string,
Record<string, EventCallback<unknown>>
> = {};