@hackdonalds/emitter
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,3 +0,6 @@ | ||
export default class Emitter { | ||
constructor(listeners = {}) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
var Emitter = /** @class */ (function () { | ||
function Emitter(listeners) { | ||
if (listeners === void 0) { listeners = {}; } | ||
this.listeners = listeners; | ||
@@ -12,6 +15,6 @@ this.listeners = listeners; | ||
*/ | ||
on(type, handler) { | ||
Emitter.prototype.on = function (type, handler) { | ||
this.listeners[type] = this.listeners[type] || []; | ||
this.listeners[type].push(handler); | ||
} | ||
}; | ||
/** | ||
@@ -23,7 +26,7 @@ * Remove an event handler for the given type. | ||
*/ | ||
off(type, handler) { | ||
Emitter.prototype.off = function (type, handler) { | ||
if (this.listeners[type]) { | ||
this.listeners[type].splice(this.listeners[type].indexOf(handler) >>> 0, 1); | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -38,10 +41,12 @@ * Invoke this.listeners handlers for the given type. | ||
*/ | ||
emit(type, evt) { | ||
(this.listeners[type] || []).slice().map((handler) => { handler(evt); }); | ||
(this.listeners['*'] || []).slice().map((handler) => { handler(type, evt); }); | ||
} | ||
} | ||
Emitter.prototype.emit = function (type, evt) { | ||
(this.listeners[type] || []).slice().map(function (handler) { handler(evt); }); | ||
(this.listeners['*'] || []).slice().map(function (handler) { handler(type, evt); }); | ||
}; | ||
return Emitter; | ||
}()); | ||
exports["default"] = Emitter; | ||
if (typeof window !== "undefined") { | ||
window.HackDonalds = { Emitter }; | ||
window.HackDonalds = { Emitter: Emitter }; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["event", "emitter", "isomorphic", "events", "nodejs", "Javascript", "mitt", "eventemitter"], | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"main": "dist/index.js", | ||
@@ -8,0 +8,0 @@ "files": ["dist","README.md","src"], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10863
136