index.d.ts 789 B

12345678910111213141516171819202122232425262728293031323334
  1. interface EventType {
  2. readonly callback: Function;
  3. readonly once: boolean;
  4. }
  5. export default class EventEmitter {
  6. private _events;
  7. /**
  8. * 监听一个事件
  9. * @param evt
  10. * @param callback
  11. * @param once
  12. */
  13. on(evt: string, callback: Function, once?: boolean): this;
  14. /**
  15. * 监听一个事件一次
  16. * @param evt
  17. * @param callback
  18. */
  19. once(evt: string, callback: Function): this;
  20. /**
  21. * 触发一个事件
  22. * @param evt
  23. * @param args
  24. */
  25. emit(evt: string, ...args: any[]): void;
  26. /**
  27. * 取消监听一个事件,或者一个channel
  28. * @param evt
  29. * @param callback
  30. */
  31. off(evt?: string, callback?: Function): this;
  32. getEvents(): Record<string, EventType[]>;
  33. }
  34. export {};