Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-event-emitter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-event-emitter - npm Package Compare versions

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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc