UNPKG

tav-ui

Version:
39 lines (35 loc) 846 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function mitt(all) { all = all || /* @__PURE__ */ new Map(); return { all, on(type, handler) { const handlers = all?.get(type); const added = handlers && handlers.push(handler); if (!added) { all?.set(type, [handler]); } }, off(type, handler) { const handlers = all?.get(type); if (handlers) { handlers.splice(handlers.indexOf(handler) >>> 0, 1); } }, emit(type, evt) { ; (all?.get(type) || []).slice().forEach((handler) => { handler(evt); }); (all?.get("*") || []).slice().forEach((handler) => { handler(type, evt); }); }, clear() { this.all.clear(); } }; } exports.mitt = mitt; //# sourceMappingURL=mitt2.js.map