-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy patheventEmitter.min.js
1 lines (1 loc) · 1.22 KB
/
eventEmitter.min.js
1
!function(){function e(t){return"function"==typeof t||!(!t||"object"!=typeof t)&&e(t.listener)}function t(e,t){if(e.indexOf)return e.indexOf(t);for(var n=-1,o=0,i=e.length;o<i;o++)if(e[o]===t){n=o;break}return n}function n(){this.__events={}}var o="object"==typeof self&&self.self==self&&self||"object"==typeof global&&global.global==global&&global||this||{};n.VERSION="1.0.0";var i=n.prototype;i.on=function(n,o){if(n&&o){if(!e(o))throw new TypeError("listener must be a function");var i=this.__events,r=i[n]=i[n]||[],f="object"==typeof o;return-1===t(r,o)&&r.push(f?o:{listener:o,once:!1}),this}},i.once=function(e,t){return this.on(e,{listener:t,once:!0})},i.off=function(e,t){var n=this.__events[e];if(n){for(var o,i=0,r=n.length;i<r;i++)if(n[i]&&n[i].listener===t){o=i;break}return void 0!==o&&n.splice(o,1,null),this}},i.emit=function(e,t){var n=this.__events[e];if(n){for(var o=0;o<n.length;o++){var i=n[o];i&&(i.listener.apply(this,t||[]),i.once&&this.off(e,i.listener))}return this}},i.allOff=function(e){e&&this.__events[e]?this.__events[e]=[]:this.__events={}},"undefined"==typeof exports||exports.nodeType?o.EventEmitter=n:("undefined"!=typeof module&&!module.nodeType&&module.exports&&(exports=module.exports=n),exports.EventEmitter=n)}();