@evergis/event-emitter
Advanced tools
Comparing version 1.0.1-alpha.0 to 1.1.0
@@ -5,4 +5,28 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
var EventEmitter = /*#__PURE__*/function () { | ||
function EventEmitter() { | ||
_classCallCheck(this, EventEmitter); | ||
this.handlers = { | ||
@@ -13,40 +37,44 @@ '*': [] | ||
var _proto = EventEmitter.prototype; | ||
_createClass(EventEmitter, [{ | ||
key: "on", | ||
value: function on(type, handler) { | ||
if (!this.handlers[type]) { | ||
this.handlers[type] = []; | ||
} | ||
_proto.on = function on(type, handler) { | ||
if (!this.handlers[type]) { | ||
this.handlers[type] = []; | ||
this.handlers[type].push(handler); | ||
} | ||
}, { | ||
key: "off", | ||
value: function off(type, handler) { | ||
if (!this.handlers[type]) return; | ||
var index = this.handlers[type].indexOf(handler); | ||
if (index === -1) return; | ||
this.handlers[type].splice(index, 1); | ||
} | ||
}, { | ||
key: "emit", | ||
value: function emit(type, event) { | ||
this.handlers[type] && this.handlers[type].map(function (handler) { | ||
return handler(event); | ||
}); | ||
this.handlers['*'].map(function (handler) { | ||
return handler(type, event); | ||
}); | ||
} | ||
}, { | ||
key: "once", | ||
value: function once(type, handler) { | ||
var _this = this; | ||
this.handlers[type].push(handler); | ||
}; | ||
var onceHandler = function onceHandler(event) { | ||
_this.off(type, onceHandler); | ||
_proto.off = function off(type, handler) { | ||
if (!this.handlers[type]) return; | ||
var index = this.handlers[type].indexOf(handler); | ||
if (index === -1) return; | ||
this.handlers[type].splice(index, 1); | ||
}; | ||
handler(event); | ||
}; | ||
_proto.emit = function emit(type, event) { | ||
this.handlers[type] && this.handlers[type].map(function (handler) { | ||
return handler(event); | ||
}); | ||
this.handlers['*'].map(function (handler) { | ||
return handler(type, event); | ||
}); | ||
}; | ||
this.on(type, onceHandler); | ||
} | ||
}]); | ||
_proto.once = function once(type, handler) { | ||
var _this = this; | ||
var onceHandler = function onceHandler(event) { | ||
_this.off(type, onceHandler); | ||
handler(event); | ||
}; | ||
this.on(type, onceHandler); | ||
}; | ||
return EventEmitter; | ||
@@ -53,0 +81,0 @@ }(); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=function(){function n(){this.handlers={"*":[]}}var t=n.prototype;return t.on=function(n,t){this.handlers[n]||(this.handlers[n]=[]),this.handlers[n].push(t)},t.off=function(n,t){if(this.handlers[n]){var e=this.handlers[n].indexOf(t);-1!==e&&this.handlers[n].splice(e,1)}},t.emit=function(n,t){this.handlers[n]&&this.handlers[n].map((function(n){return n(t)})),this.handlers["*"].map((function(e){return e(n,t)}))},t.once=function(n,t){var e=this;this.on(n,(function s(i){e.off(n,s),t(i)}))},n}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=function(){function e(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.handlers={"*":[]}}var n;return(n=[{key:"on",value:function(e,n){this.handlers[e]||(this.handlers[e]=[]),this.handlers[e].push(n)}},{key:"off",value:function(e,n){if(this.handlers[e]){var t=this.handlers[e].indexOf(n);-1!==t&&this.handlers[e].splice(t,1)}}},{key:"emit",value:function(e,n){this.handlers[e]&&this.handlers[e].map((function(e){return e(n)})),this.handlers["*"].map((function(t){return t(e,n)}))}},{key:"once",value:function(e,n){var t=this;this.on(e,(function r(i){t.off(e,r),n(i)}))}}])&&function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,n),e}(); | ||
//# sourceMappingURL=event-emitter.cjs.production.min.js.map |
@@ -0,3 +1,27 @@ | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
var EventEmitter = /*#__PURE__*/function () { | ||
function EventEmitter() { | ||
_classCallCheck(this, EventEmitter); | ||
this.handlers = { | ||
@@ -8,40 +32,44 @@ '*': [] | ||
var _proto = EventEmitter.prototype; | ||
_createClass(EventEmitter, [{ | ||
key: "on", | ||
value: function on(type, handler) { | ||
if (!this.handlers[type]) { | ||
this.handlers[type] = []; | ||
} | ||
_proto.on = function on(type, handler) { | ||
if (!this.handlers[type]) { | ||
this.handlers[type] = []; | ||
this.handlers[type].push(handler); | ||
} | ||
}, { | ||
key: "off", | ||
value: function off(type, handler) { | ||
if (!this.handlers[type]) return; | ||
var index = this.handlers[type].indexOf(handler); | ||
if (index === -1) return; | ||
this.handlers[type].splice(index, 1); | ||
} | ||
}, { | ||
key: "emit", | ||
value: function emit(type, event) { | ||
this.handlers[type] && this.handlers[type].map(function (handler) { | ||
return handler(event); | ||
}); | ||
this.handlers['*'].map(function (handler) { | ||
return handler(type, event); | ||
}); | ||
} | ||
}, { | ||
key: "once", | ||
value: function once(type, handler) { | ||
var _this = this; | ||
this.handlers[type].push(handler); | ||
}; | ||
var onceHandler = function onceHandler(event) { | ||
_this.off(type, onceHandler); | ||
_proto.off = function off(type, handler) { | ||
if (!this.handlers[type]) return; | ||
var index = this.handlers[type].indexOf(handler); | ||
if (index === -1) return; | ||
this.handlers[type].splice(index, 1); | ||
}; | ||
handler(event); | ||
}; | ||
_proto.emit = function emit(type, event) { | ||
this.handlers[type] && this.handlers[type].map(function (handler) { | ||
return handler(event); | ||
}); | ||
this.handlers['*'].map(function (handler) { | ||
return handler(type, event); | ||
}); | ||
}; | ||
this.on(type, onceHandler); | ||
} | ||
}]); | ||
_proto.once = function once(type, handler) { | ||
var _this = this; | ||
var onceHandler = function onceHandler(event) { | ||
_this.off(type, onceHandler); | ||
handler(event); | ||
}; | ||
this.on(type, onceHandler); | ||
}; | ||
return EventEmitter; | ||
@@ -48,0 +76,0 @@ }(); |
{ | ||
"version": "1.0.1-alpha.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17424
198
1
0