@mundoit-lib/plugin-vue-event
Version:
Vue 3 plugin to handle global events between components, inspired by vue-events. This plugin provides a simple and efficient event bus system, allowing to emit, listen and unregister events in an intuitive way. Compatible with Vue 2 and Vue 3.
16 lines (13 loc) • 822 B
text/typescript
import { EventType, Emitter, Handler } from 'mitt';
type EventBusEvents = Record<EventType, any>;
type UnwrappedHandler<T = any> = (...args: any[]) => T;
declare const eventBus: Emitter<EventBusEvents>;
interface EventBusInstance {
emit<K extends keyof EventBusEvents>(event: K, ...args: any[]): void;
on<K extends keyof EventBusEvents>(event: K, callback: UnwrappedHandler): Handler<EventBusEvents[K]>;
fire<K extends keyof EventBusEvents>(event: K, ...args: any[]): void;
off<K extends keyof EventBusEvents>(event: K, listener: Handler<EventBusEvents[K]>): void;
once<K extends keyof EventBusEvents>(event: K, callback: UnwrappedHandler): Handler<EventBusEvents[K]>;
}
declare const useEventBus: () => EventBusInstance;
export { type EventBusEvents, type EventBusInstance, eventBus, useEventBus };