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

@nodeart/event_emitter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodeart/event_emitter - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

.travis.yml

25

dist/index.js

@@ -54,7 +54,5 @@ "use strict";

EventEmitter.prototype.emit = function (eventName) {
var _this = this;
for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
args[_key4 - 1] = arguments[_key4];
EventEmitter.prototype.emit = function (eventName, ctx) {
for (var _len4 = arguments.length, args = Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
args[_key4 - 2] = arguments[_key4];
}

@@ -64,3 +62,3 @@

this.events[eventName] = this.events[eventName].filter(function (elem) {
elem.fn.apply(_this, args);
elem.fn.apply(ctx, args);
return !elem.once;

@@ -77,5 +75,14 @@ });

if (!this.events[eventName]) return this;
fns.length > 0 ? this.events[eventName] = this.events[eventName].filter(function (listener) {
return !fns.includes(listener.fn);
}) : delete this.events[eventName];
if (fns.length) {
var tasksLeft = this.events[eventName].filter(function (listener) {
return !fns.includes(listener.fn);
});
if (tasksLeft.length) {
this.events[eventName] = tasksLeft;
} else {
delete this.events[eventName];
}
} else {
delete this.events[eventName];
}
return this;

@@ -82,0 +89,0 @@ };

@@ -1,1 +0,1 @@

"use strict";!function t(e,n,r){function i(u,f){if(!n[u]){if(!e[u]){var s="function"==typeof require&&require;if(!f&&s)return s(u,!0);if(o)return o(u,!0);throw new Error("Cannot find module '"+u+"'")}var h=n[u]={exports:{}};e[u][0].call(h.exports,function(t){var n=e[u][1][t];return i(n?n:t)},h,h.exports,t,e,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(t,e,n){function r(){this.events={}}var i=function(t){return function(e){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return this.events[e]=r.reduce(function(e,n){return e.push({fn:n,once:t}),e},this.events[e]||[]),this}},o=i(!1),u=i(!0);r.prototype.on=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return o.apply(this,e)},r.prototype.once=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return u.apply(this,e)},r.prototype.emit=function(t){for(var e=this,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return this.events[t]?(this.events[t]=this.events[t].filter(function(t){return t.fn.apply(e,r),!t.once}),this):this},r.prototype.off=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return this.events[t]?(n.length>0?this.events[t]=this.events[t].filter(function(t){return!n.includes(t.fn)}):delete this.events[t],this):this},r.prototype.offAll=function(){return this.events={},this},void 0!==e&&e.exports&&(e.exports=r),"undefined"!=typeof window&&document&&(window.EventEmitter=r)},{}]},{},[1]);
"use strict";!function t(e,n,r){function i(u,f){if(!n[u]){if(!e[u]){var s="function"==typeof require&&require;if(!f&&s)return s(u,!0);if(o)return o(u,!0);throw new Error("Cannot find module '"+u+"'")}var h=n[u]={exports:{}};e[u][0].call(h.exports,function(t){var n=e[u][1][t];return i(n?n:t)},h,h.exports,t,e,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(t,e,n){function r(){this.events={}}var i=function(t){return function(e){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return this.events[e]=r.reduce(function(e,n){return e.push({fn:n,once:t}),e},this.events[e]||[]),this}},o=i(!1),u=i(!0);r.prototype.on=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return o.apply(this,e)},r.prototype.once=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return u.apply(this,e)},r.prototype.emit=function(t,e){for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];return this.events[t]?(this.events[t]=this.events[t].filter(function(t){return t.fn.apply(e,r),!t.once}),this):this},r.prototype.off=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];if(!this.events[t])return this;if(n.length){var i=this.events[t].filter(function(t){return!n.includes(t.fn)});i.length?this.events[t]=i:delete this.events[t]}else delete this.events[t];return this},r.prototype.offAll=function(){return this.events={},this},void 0!==e&&e.exports&&(e.exports=r),"undefined"!=typeof window&&document&&(window.EventEmitter=r)},{}]},{},[1]);
{
"name": "@nodeart/event_emitter",
"version": "1.0.5",
"version": "1.0.6",
"description": "Simple EventEmitter pattern",

@@ -13,3 +13,3 @@ "main": "./src/index.js",

"build": "gulp build",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node ./tests.js"
},

@@ -30,4 +30,7 @@ "keywords": [

},
"engines": {
"node": ">=6.0.0"
},
"author": "Ivan Prodaiko",
"license": "MIT"
}

@@ -9,7 +9,9 @@ [![bitHound Overall Score](https://www.bithound.io/github/NodeArt/EventEmitter/badges/score.svg)](https://www.bithound.io/github/NodeArt/EventEmitter)

const events = new EventEmitter();
events.on(eventName, ...fns)
events.once(eventName, ...fns)
events.off(eventName, ...fns)
events.offAll()
events.emit(eventName, ...args)
events.on('eventName', ...fns);
events.once('eventName', ...fns);
events.off('eventName', ...fns);
events.offAll();
events.emit('eventName', {
ctx: true
}, ...args);
// One can remove some functions from listeners array by passing them to .off method,

@@ -21,3 +23,3 @@ // but to remove particular event use .off with eventName only;

2) chaining available
3) can be used in node.js and in browser
3) can be used in node.js and in browser

@@ -27,6 +27,6 @@ "use strict";

EventEmitter.prototype.emit = function(eventName, ...args) {
EventEmitter.prototype.emit = function(eventName, ctx, ...args) {
if (!this.events[eventName]) return this;
this.events[eventName] = this.events[eventName].filter(elem => {
elem.fn.apply(this, args);
elem.fn.apply(ctx, args);
return !elem.once;

@@ -39,5 +39,12 @@ });

if (!this.events[eventName]) return this;
fns.length > 0 ?
this.events[eventName] = this.events[eventName].filter(listener => !fns.includes(listener.fn)) :
if (fns.length) {
const tasksLeft = this.events[eventName].filter(listener => !fns.includes(listener.fn));
if (tasksLeft.length) {
this.events[eventName] = tasksLeft;
} else {
delete this.events[eventName];
}
} else {
delete this.events[eventName];
}
return this;

@@ -44,0 +51,0 @@ };

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