@polyv/utils
Version:
Utility functions of Polyv frontend development.
1 lines • 922 B
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=void 0;var EventEmitter=function(){function t(){this.__eventStore={}}return t.prototype.__addOnEvent=function(t,e,n,o){if(e&&n){var r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}},t.prototype.on=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("normal",t,e,n)},t.prototype.once=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("once",t,e,n)},t.prototype.off=function(t,e){var n=this.__eventStore[t];n&&(n=n.filter((function(t){return t.handler!==e})),this.__eventStore[t]=n)},t.prototype.emit=function(t,e){var n=this,o=this.__eventStore[t];o&&o.forEach((function(o){var r=o.type,i=o.handler,v=o.callbackHandler;"function"==typeof v&&v(e),"once"===r&&n.off(t,i)}))},t.prototype.destroy=function(){this.__eventStore={}},t}();exports.EventEmitter=EventEmitter;