mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 18:14:49 +00:00
* refactor: app event bus * fix: use messagepack + cleanup * fix: use postcard * fix: lint * fix: import gate * fix: prettierignore + lint * fix: lint * fix: rev
20 lines
685 B
TypeScript
20 lines
685 B
TypeScript
import { createContext } from '@modrinth/ui'
|
|
|
|
import type { AppEvent } from '@/generated/app-events/AppEvent'
|
|
|
|
export type AppEventType = AppEvent['type']
|
|
export type AppEventPayload<Type extends AppEventType> = Extract<
|
|
AppEvent,
|
|
{ type: Type }
|
|
>['payload']
|
|
export type AppEventHandler<Type extends AppEventType> = (
|
|
payload: AppEventPayload<Type>,
|
|
) => void | Promise<void>
|
|
|
|
export interface AppEvents {
|
|
on<Type extends AppEventType>(type: Type, handler: AppEventHandler<Type>): () => void
|
|
once<Type extends AppEventType>(type: Type, handler: AppEventHandler<Type>): () => void
|
|
}
|
|
|
|
export const [injectAppEvents, provideAppEvents] = createContext<AppEvents>('root', 'appEvents')
|