Comparing version 2.1.1 to 2.2.0
/*! | ||
* uevent (v2.1.1) | ||
* uevent (v2.2.0) | ||
* @copyright 2015-2022 Damien "Mistic" Sorel <contact@git.strangeplanet.fr> | ||
@@ -133,10 +133,16 @@ * @licence MIT | ||
this.__events = this.__events || {}; | ||
if (typeof events === 'object') { | ||
for (var event in events) { | ||
if (events.hasOwnProperty(event) && event in this.__events) { | ||
var index = this.__events[event].indexOf(events[event]); | ||
if (events.hasOwnProperty(event)) { | ||
if (this.__events && event in this.__events) { | ||
var index = this.__events[event].indexOf(events[event]); | ||
if (index !== -1) this.__events[event].splice(index, 1); | ||
if (index !== -1) this.__events[event].splice(index, 1); | ||
} | ||
if (this.__once && event in this.__once) { | ||
var _index = this.__once[event].indexOf(events[event]); | ||
if (_index !== -1) this.__once[event].splice(_index, 1); | ||
} | ||
} | ||
@@ -146,7 +152,7 @@ } | ||
events.split(' ').forEach(function (event) { | ||
if (event in _this2.__events) { | ||
if (_this2.__events && event in _this2.__events) { | ||
if (callback) { | ||
var _index = _this2.__events[event].indexOf(callback); | ||
var _index2 = _this2.__events[event].indexOf(callback); | ||
if (_index !== -1) _this2.__events[event].splice(_index, 1); | ||
if (_index2 !== -1) _this2.__events[event].splice(_index2, 1); | ||
} else { | ||
@@ -156,5 +162,16 @@ _this2.__events[event].length = 0; | ||
} | ||
if (_this2.__once && event in _this2.__once) { | ||
if (callback) { | ||
var _index3 = _this2.__once[event].indexOf(callback); | ||
if (_index3 !== -1) _this2.__once[event].splice(_index3, 1); | ||
} else { | ||
_this2.__once[event].length = 0; | ||
} | ||
} | ||
}); | ||
} else { | ||
this.__events = {}; | ||
this.__once = {}; | ||
} | ||
@@ -161,0 +178,0 @@ |
{ | ||
"name": "uevent", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Event emitter micro library", | ||
@@ -35,3 +35,3 @@ "main": "index.js", | ||
"@babel/preset-env": "^7.16.11", | ||
"mocha": "^9.2.0", | ||
"mocha": "^10.0.0", | ||
"rollup": "^2.66.1", | ||
@@ -38,0 +38,0 @@ "rollup-plugin-babel": "^4.4.0", |
@@ -58,9 +58,13 @@ const Event = require('./Event'); | ||
off(events, callback) { | ||
this.__events = this.__events || {}; | ||
if (typeof events === 'object') { | ||
for (const event in events) { | ||
if (events.hasOwnProperty(event) && (event in this.__events)) { | ||
const index = this.__events[event].indexOf(events[event]); | ||
if (index !== -1) this.__events[event].splice(index, 1); | ||
if (events.hasOwnProperty(event)) { | ||
if (this.__events && (event in this.__events)) { | ||
const index = this.__events[event].indexOf(events[event]); | ||
if (index !== -1) this.__events[event].splice(index, 1); | ||
} | ||
if (this.__once && (event in this.__once)) { | ||
const index = this.__once[event].indexOf(events[event]); | ||
if (index !== -1) this.__once[event].splice(index, 1); | ||
} | ||
} | ||
@@ -71,3 +75,3 @@ } | ||
events.split(' ').forEach((event) => { | ||
if (event in this.__events) { | ||
if (this.__events && (event in this.__events)) { | ||
if (callback) { | ||
@@ -81,2 +85,11 @@ const index = this.__events[event].indexOf(callback); | ||
} | ||
if (this.__once && (event in this.__once)) { | ||
if (callback) { | ||
const index = this.__once[event].indexOf(callback); | ||
if (index !== -1) this.__once[event].splice(index, 1); | ||
} | ||
else { | ||
this.__once[event].length = 0; | ||
} | ||
} | ||
}); | ||
@@ -86,2 +99,3 @@ } | ||
this.__events = {}; | ||
this.__once = {}; | ||
} | ||
@@ -137,3 +151,3 @@ | ||
if (this.__events && event in this.__events) { | ||
if (this.__events && (event in this.__events)) { | ||
for (let i = 0, l = this.__events[event].length; i < l; i++) { | ||
@@ -153,3 +167,3 @@ const f = this.__events[event][i]; | ||
if (this.__once && event in this.__once) { | ||
if (this.__once && (event in this.__once)) { | ||
for (let i = 0, l = this.__once[event].length; i < l; i++) { | ||
@@ -156,0 +170,0 @@ const f = this.__once[event][i]; |
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
41370
576