mitt.d.ts 1.1 KB

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