mitt.js 615 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = mitt;
  6. function mitt() {
  7. const all = Object.create(null);
  8. return {
  9. on (type, handler) {
  10. (all[type] || (all[type] = [])).push(handler);
  11. },
  12. off (type, handler) {
  13. if (all[type]) {
  14. all[type].splice(all[type].indexOf(handler) >>> 0, 1);
  15. }
  16. },
  17. emit (type, ...evts) {
  18. (all[type] || []).slice().map((handler)=>{
  19. handler(...evts);
  20. });
  21. }
  22. };
  23. }
  24. //# sourceMappingURL=mitt.js.map