-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-bus.js
3 lines (3 loc) · 1.12 KB
/
event-bus.js
1
2
3
/*! For license information please see event-bus.js.LICENSE.txt */
var EventBus;(()=>{"use strict";var e={d:(s,t)=>{for(var r in t)e.o(t,r)&&!e.o(s,r)&&Object.defineProperty(s,r,{enumerable:!0,get:t[r]})},o:(e,s)=>Object.prototype.hasOwnProperty.call(e,s)},s={};(()=>{e.d(s,{default:()=>t});const t=class{constructor(){this.listeners={}}on(e,s){return this.registerListener(e,s,s),this}registerListener(e,s,t){this.listeners.hasOwnProperty(e)||(this.listeners[e]=new Map),this.listeners[e].set(s,t)}off(e,s){return this.listeners.hasOwnProperty(e)&&(void 0!==s?this.unregisterListener(e,s):this.unregisterAllListeners(e)),this}unregisterListener(e,s){this.listeners[e].delete(s)&&this.removeListenersMapIfEmpty(e)}removeListenersMapIfEmpty(e){0===this.listeners[e].size&&this.unregisterAllListeners(e)}unregisterAllListeners(e){delete this.listeners[e]}once(e,s){return this.registerListener(e,s,((...t)=>{s(...t),this.off(e,s)})),this}trigger(e,...s){if(this.listeners.hasOwnProperty(e))for(const t of this.listeners[e].values())try{t(...s)}catch(e){console.error(e)}return this}}})(),EventBus=s.default})();
//# sourceMappingURL=event-bus.js.map