Socket
Socket
Sign inDemoInstall

@thednp/event-listener

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

13

dist/event-listener-es5.js
/*!
* EventListener v1.0.0 (https://github.com/thednp/event-listener.js)
* EventListener v1.0.1 (https://github.com/thednp/event-listener.js)
* Modern event listener for efficient applications based on subscribe-publish pattern.

@@ -25,2 +25,3 @@ * Copyright 2022 © thednp

var type = e.type;
var target = e.target;

@@ -30,4 +31,5 @@ [].concat( EventRegistry[type] ).forEach(function (elementsMap) {

var listenersMap = elementsMap[1];
[].concat( listenersMap ).forEach(function (listenerMap) {
if (element === that) {
/* istanbul ignore else */
if ([target, that].some(function (el) { return element === el; })) {
[].concat( listenersMap ).forEach(function (listenerMap) {
var listener = listenerMap[0];

@@ -40,4 +42,4 @@ var options = listenerMap[1];

}
}
});
});
}
});

@@ -100,2 +102,3 @@ }

// remove listener last
/* istanbul ignore else */
if (!oneElementMap || !oneElementMap.size) {

@@ -102,0 +105,0 @@ element.removeEventListener(eventType, globalListener, eventOptions);

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

// EventListener v1.0.0 | thednp © 2022 | MIT-License
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).EventListener=t()}(this,(function(){"use strict";var e={};function t(t){var o=this,i=t.type;[].concat(e[i]).forEach((function(e){var s=e[0],f=e[1];[].concat(f).forEach((function(e){if(s===o){var f=e[0],a=e[1];f.apply(s,[t]),a&&a.once&&n(s,i,f,a)}}))}))}var n=function(n,o,i,s){var f=e[o],a=f&&f.get(n),r=a&&a.get(i),c=(void 0!==r?r:{options:s}).options;a&&a.has(i)&&a.delete(i),!f||a&&a.size||f.delete(n),f&&f.size||delete e[o],a&&a.size||n.removeEventListener(o,t,c)};return{on:function(n,o,i,s){e[o]||(e[o]=new Map);var f=e[o];f.has(n)||f.set(n,new Map);var a=f.get(n),r=a.size;a.set(i,s),r||n.addEventListener(o,t,s)},off:n,globalListener:t,registry:e}}));
// EventListener v1.0.1 | thednp © 2022 | MIT-License
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).EventListener=t()}(this,(function(){"use strict";var e={};function t(t){var o=this,i=t.type,r=t.target;[].concat(e[i]).forEach((function(e){var s=e[0],a=e[1];[r,o].some((function(e){return s===e}))&&[].concat(a).forEach((function(e){var o=e[0],r=e[1];o.apply(s,[t]),r&&r.once&&n(s,i,o,r)}))}))}var n=function(n,o,i,r){var s=e[o],a=s&&s.get(n),f=a&&a.get(i),c=(void 0!==f?f:{options:r}).options;a&&a.has(i)&&a.delete(i),!s||a&&a.size||s.delete(n),s&&s.size||delete e[o],a&&a.size||n.removeEventListener(o,t,c)};return{on:function(n,o,i,r){e[o]||(e[o]=new Map);var s=e[o];s.has(n)||s.set(n,new Map);var a=s.get(n),f=a.size;a.set(i,r),f||n.addEventListener(o,t,r)},off:n,globalListener:t,registry:e}}));
/*!
* EventListener v1.0.0 (https://github.com/thednp/event-listener.js)
* EventListener v1.0.1 (https://github.com/thednp/event-listener.js)
* Modern event listener for efficient applications based on subscribe-publish pattern.

@@ -18,8 +18,9 @@ * Copyright 2022 © thednp

const that = this;
const { type } = e;
const { type, target } = e;
[...EventRegistry[type]].forEach((elementsMap) => {
const [element, listenersMap] = elementsMap;
[...listenersMap].forEach((listenerMap) => {
if (element === that) {
/* istanbul ignore else */
if ([target, that].some((el) => element === el)) {
[...listenersMap].forEach((listenerMap) => {
const [listener, options] = listenerMap;

@@ -31,4 +32,4 @@ listener.apply(element, [e]);

}
}
});
});
}
});

@@ -90,2 +91,3 @@ }

// remove listener last
/* istanbul ignore else */
if (!oneElementMap || !oneElementMap.size) {

@@ -92,0 +94,0 @@ element.removeEventListener(eventType, globalListener, eventOptions);

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

// EventListener v1.0.0 | thednp © 2022 | MIT-License
const e={};function t(t){const o=this,{type:n}=t;[...e[n]].forEach(e=>{const[i,c]=e;[...c].forEach(e=>{if(i===o){const[o,c]=e;o.apply(i,[t]),c&&c.once&&s(i,n,o,c)}})})}const s=(s,o,n,i)=>{const c=e[o],a=c&&c.get(s),r=a&&a.get(n),{options:p}=void 0!==r?r:{options:i};a&&a.has(n)&&a.delete(n),!c||a&&a.size||c.delete(s),c&&c.size||delete e[o],a&&a.size||s.removeEventListener(o,t,p)},o={on:(s,o,n,i)=>{e[o]||(e[o]=new Map);const c=e[o];c.has(s)||c.set(s,new Map);const a=c.get(s),{size:r}=a;a.set(n,i),r||s.addEventListener(o,t,i)},off:s,globalListener:t,registry:e};export{o as default};
// EventListener v1.0.1 | thednp © 2022 | MIT-License
const e={};function t(t){const o=this,{type:n,target:i}=t;[...e[n]].forEach(e=>{const[a,c]=e;[i,o].some(e=>a===e)&&[...c].forEach(e=>{const[o,i]=e;o.apply(a,[t]),i&&i.once&&s(a,n,o,i)})})}const s=(s,o,n,i)=>{const a=e[o],c=a&&a.get(s),r=c&&c.get(n),{options:p}=void 0!==r?r:{options:i};c&&c.has(n)&&c.delete(n),!a||c&&c.size||a.delete(s),a&&a.size||delete e[o],c&&c.size||s.removeEventListener(o,t,p)},o={on:(s,o,n,i)=>{e[o]||(e[o]=new Map);const a=e[o];a.has(s)||a.set(s,new Map);const c=a.get(s),{size:r}=c;c.set(n,i),r||s.addEventListener(o,t,i)},off:s,globalListener:t,registry:e};export{o as default};
/*!
* EventListener v1.0.0 (https://github.com/thednp/event-listener.js)
* EventListener v1.0.1 (https://github.com/thednp/event-listener.js)
* Modern event listener for efficient applications based on subscribe-publish pattern.

@@ -24,8 +24,9 @@ * Copyright 2022 © thednp

const that = this;
const { type } = e;
const { type, target } = e;
[...EventRegistry[type]].forEach((elementsMap) => {
const [element, listenersMap] = elementsMap;
[...listenersMap].forEach((listenerMap) => {
if (element === that) {
/* istanbul ignore else */
if ([target, that].some((el) => element === el)) {
[...listenersMap].forEach((listenerMap) => {
const [listener, options] = listenerMap;

@@ -37,4 +38,4 @@ listener.apply(element, [e]);

}
}
});
});
}
});

@@ -96,2 +97,3 @@ }

// remove listener last
/* istanbul ignore else */
if (!oneElementMap || !oneElementMap.size) {

@@ -98,0 +100,0 @@ element.removeEventListener(eventType, globalListener, eventOptions);

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

// EventListener v1.0.0 | thednp © 2022 | MIT-License
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).EventListener=t()}(this,(function(){"use strict";const e={};function t(t){const o=this,{type:s}=t;[...e[s]].forEach(e=>{const[i,f]=e;[...f].forEach(e=>{if(i===o){const[o,f]=e;o.apply(i,[t]),f&&f.once&&n(i,s,o,f)}})})}const n=(n,o,s,i)=>{const f=e[o],c=f&&f.get(n),d=c&&c.get(s),{options:r}=void 0!==d?d:{options:i};c&&c.has(s)&&c.delete(s),!f||c&&c.size||f.delete(n),f&&f.size||delete e[o],c&&c.size||n.removeEventListener(o,t,r)};return{on:(n,o,s,i)=>{e[o]||(e[o]=new Map);const f=e[o];f.has(n)||f.set(n,new Map);const c=f.get(n),{size:d}=c;c.set(s,i),d||n.addEventListener(o,t,i)},off:n,globalListener:t,registry:e}}));
// EventListener v1.0.1 | thednp © 2022 | MIT-License
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).EventListener=t()}(this,(function(){"use strict";const e={};function t(t){const o=this,{type:s,target:i}=t;[...e[s]].forEach(e=>{const[f,c]=e;[i,o].some(e=>f===e)&&[...c].forEach(e=>{const[o,i]=e;o.apply(f,[t]),i&&i.once&&n(f,s,o,i)})})}const n=(n,o,s,i)=>{const f=e[o],c=f&&f.get(n),d=c&&c.get(s),{options:r}=void 0!==d?d:{options:i};c&&c.has(s)&&c.delete(s),!f||c&&c.size||f.delete(n),f&&f.size||delete e[o],c&&c.size||n.removeEventListener(o,t,r)};return{on:(n,o,s,i)=>{e[o]||(e[o]=new Map);const f=e[o];f.has(n)||f.set(n,new Map);const c=f.get(n),{size:d}=c;c.set(s,i),d||n.addEventListener(o,t,i)},off:n,globalListener:t,registry:e}}));
{
"name": "@thednp/event-listener",
"author": "thednp",
"version": "1.0.0",
"version": "1.0.1",
"description": "Modern event listener for efficient applications based on subscribe-publish pattern.",

@@ -55,3 +55,3 @@ "license": "MIT",

"@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
"@cypress/code-coverage": "^3.9.12",
"@cypress/code-coverage": "^3.9.12",
"@rollup/plugin-buble": "^0.21.3",

@@ -67,4 +67,5 @@ "@rollup/plugin-json": "^4.1.0",

"istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-instrument": "^5.2.0",
"istanbul-lib-instrument": "^5.2.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"rollup": "^2.38.5",

@@ -71,0 +72,0 @@ "rollup-plugin-terser": "^5.3.1",

@@ -1,2 +0,3 @@

# EventListener [![Coverage Status](https://coveralls.io/repos/github/thednp/event-listener/badge.svg?branch=main)](https://coveralls.io/github/thednp/event-listener?branch=main) ![cypress version](https://img.shields.io/badge/cypress-9.6.0-brightgreen) ![typescript version](https://img.shields.io/badge/typescript-4.5.2-brightgreen)
# EventListener [![Coverage Status](https://coveralls.io/repos/github/thednp/event-listener/badge.svg?branch=main)](https://coveralls.io/github/thednp/event-listener?branch=main) ![cypress version](https://img.shields.io/badge/cypress-9.6.0-brightgreen) ![typescript version](https://img.shields.io/badge/typescript-4.5.2-brightgreen) [![ci](https://github.com/thednp/event-listener/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/thednp/event-listener/actions/workflows/ci.yml)
Modern event listener for efficient applications based on the [subscribe-publish](https://hackernoon.com/do-you-still-register-window-event-listeners-in-each-component-react-in-example-31a4b1f6f1c8) pattern.

@@ -3,0 +4,0 @@

@@ -14,8 +14,9 @@ /** @type {Record<string, any>} */

const that = this;
const { type } = e;
const { type, target } = e;
[...EventRegistry[type]].forEach((elementsMap) => {
const [element, listenersMap] = elementsMap;
[...listenersMap].forEach((listenerMap) => {
if (element === that) {
/* istanbul ignore else */
if ([target, that].some((el) => element === el)) {
[...listenersMap].forEach((listenerMap) => {
const [listener, options] = listenerMap;

@@ -27,4 +28,4 @@ listener.apply(element, [e]);

}
}
});
});
}
});

@@ -86,2 +87,3 @@ }

// remove listener last
/* istanbul ignore else */
if (!oneElementMap || !oneElementMap.size) {

@@ -88,0 +90,0 @@ element.removeEventListener(eventType, globalListener, eventOptions);

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc