mitt.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. declare var mitt: mitt.MittStatic;
  2. declare module "mitt" {
  3. export = mitt;
  4. }
  5. declare namespace mitt {
  6. type Handler = (event?: any) => void;
  7. type WildcardHandler = (type?: string, event?: any) => void;
  8. interface MittStatic {
  9. (all?: {[key: string]: Array<Handler>}): Emitter;
  10. }
  11. interface Emitter {
  12. /**
  13. * Register an event handler for the given type.
  14. *
  15. * @param {string} type Type of event to listen for, or `"*"` for all events.
  16. * @param {Handler} handler Function to call in response to the given event.
  17. *
  18. * @memberOf Mitt
  19. */
  20. on(type: string, handler: Handler): void;
  21. on(type: "*", handler: WildcardHandler): void;
  22. /**
  23. * Function to call in response to the given event
  24. *
  25. * @param {string} type Type of event to unregister `handler` from, or `"*"`
  26. * @param {Handler} handler Handler function to remove.
  27. *
  28. * @memberOf Mitt
  29. */
  30. off(type: string, handler: Handler): void;
  31. off(type: "*", handler: WildcardHandler): void;
  32. /**
  33. * Invoke all handlers for the given type.
  34. * If present, `"*"` handlers are invoked prior to type-matched handlers.
  35. *
  36. * @param {string} type The event type to invoke
  37. * @param {any} [event] An event object, passed to each handler
  38. *
  39. * @memberOf Mitt
  40. */
  41. emit(type: string, event?: any): void;
  42. }
  43. }