@nodeart/event_emitter
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "@nodeart/event_emitter", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Simple EventEmitter pattern", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -5,5 +5,5 @@ "use strict"; | ||
return function(eventName, ...args) { | ||
const arrOfSubscribers = this.events[eventName] || []; | ||
args.forEach(fn => arrOfSubscribers.push({ fn: fn, once: once })); | ||
this.events[eventName] = arrOfSubscribers; | ||
const eventsArr = this.events[eventName] || []; | ||
args.forEach(fn => eventsArr.push({ fn: fn, once: once })); | ||
this.events[eventName] = eventsArr; | ||
return this; | ||
@@ -29,9 +29,6 @@ }; | ||
if (!this.events[eventName]) return this; | ||
for (let i = 0; i < this.events[eventName].length; i++) { | ||
let obj = this.events[eventName][i]; | ||
obj.fn(...args); | ||
if (obj.once) { | ||
this.events[eventName].splice(i, 1); | ||
} | ||
} | ||
this.events[eventName] = this.events[eventName].filter(elem => { | ||
elem.fn(...args); | ||
return !elem.once; | ||
}); | ||
return this; | ||
@@ -38,0 +35,0 @@ }; |
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
10120
142