typed-event-emitter
Advanced tools
Comparing version 1.0.3 to 1.1.0
61
index.js
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/****************************************************************************** | ||
@@ -24,8 +25,8 @@ * The MIT License (MIT) * | ||
******************************************************************************/ | ||
"use strict"; | ||
class EventEmitter { | ||
constructor() { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var EventEmitter = /** @class */ (function () { | ||
function EventEmitter() { | ||
this.eventListeners = new Map(); | ||
} | ||
on(event, listener) { | ||
EventEmitter.prototype.on = function (event, listener) { | ||
if (!this.eventListeners.has(event)) { | ||
@@ -38,7 +39,7 @@ this.eventListeners.set(event, [listener]); | ||
return new Listener(this, event, listener); | ||
} | ||
addListener(event, listener) { | ||
}; | ||
EventEmitter.prototype.addListener = function (event, listener) { | ||
return this.on(event, listener); | ||
} | ||
removeListener() { | ||
}; | ||
EventEmitter.prototype.removeListener = function () { | ||
if (arguments.length == 0) { | ||
@@ -48,8 +49,8 @@ this.eventListeners.clear(); | ||
else if (arguments.length == 1 && typeof arguments[0] == 'object') { | ||
let id = arguments[0]; | ||
var id = arguments[0]; | ||
this.removeListener(id.event, id.listener); | ||
} | ||
else if (arguments.length >= 1) { | ||
let event = arguments[0]; | ||
let listener = arguments[1]; | ||
var event = arguments[0]; | ||
var listener = arguments[1]; | ||
if (this.eventListeners.has(event)) { | ||
@@ -63,26 +64,33 @@ var listeners = this.eventListeners.get(event); | ||
} | ||
} | ||
}; | ||
/** | ||
* Emit event. Calls all bound listeners with args. | ||
*/ | ||
emit(event, ...args) { | ||
EventEmitter.prototype.emit = function (event) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
if (this.eventListeners.has(event)) { | ||
for (var listener of this.eventListeners.get(event)) { | ||
listener(...args); | ||
for (var _a = 0, _b = this.eventListeners.get(event); _a < _b.length; _a++) { | ||
var listener = _b[_a]; | ||
listener.apply(void 0, args); | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* @typeparam T The event handler signature. | ||
*/ | ||
registerEvent() { | ||
let eventBinder = (handler) => { | ||
return this.addListener(eventBinder, handler); | ||
EventEmitter.prototype.registerEvent = function () { | ||
var _this = this; | ||
var eventBinder = function (handler) { | ||
return _this.addListener(eventBinder, handler); | ||
}; | ||
return eventBinder; | ||
} | ||
} | ||
}; | ||
return EventEmitter; | ||
}()); | ||
exports.EventEmitter = EventEmitter; | ||
class Listener { | ||
constructor(owner, event, listener) { | ||
var Listener = /** @class */ (function () { | ||
function Listener(owner, event, listener) { | ||
this.owner = owner; | ||
@@ -92,7 +100,8 @@ this.event = event; | ||
} | ||
unbind() { | ||
Listener.prototype.unbind = function () { | ||
this.owner.removeListener(this); | ||
} | ||
} | ||
}; | ||
return Listener; | ||
}()); | ||
exports.Listener = Listener; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "typed-event-emitter", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Alternative event emitter for JavaScript and TypeScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
10783
148