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

emittery

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emittery - npm Package Compare versions

Comparing version 0.12.1 to 0.13.0

76

index.js
'use strict';
const anyMap = new WeakMap();
const eventsMap = new WeakMap();
const producersMap = new WeakMap();
const {anyMap, producersMap, eventsMap} = require('./maps.js');
const anyProducer = Symbol('anyProducer');

@@ -31,3 +30,3 @@ const resolvedPromise = Promise.resolve();

if (!events.has(eventName)) {
events.set(eventName, new Set());
return;
}

@@ -42,3 +41,3 @@

if (!producers.has(key)) {
producers.set(key, new Set());
return;
}

@@ -84,3 +83,10 @@

for (const eventName of eventNames) {
getEventProducers(instance, eventName).add(producer);
let set = getEventProducers(instance, eventName);
if (!set) {
set = new Set();
const producers = producersMap.get(instance);
producers.set(eventName, set);
}
set.add(producer);
}

@@ -117,3 +123,10 @@

for (const eventName of eventNames) {
getEventProducers(instance, eventName).delete(producer);
const set = getEventProducers(instance, eventName);
if (set) {
set.delete(producer);
if (set.size === 0) {
const producers = producersMap.get(instance);
producers.delete(eventName);
}
}
}

@@ -228,2 +241,5 @@

producersMap.set(this, new Map());
producersMap.get(this).set(anyProducer, new Set());
this.debug = options.debug || {};

@@ -267,4 +283,11 @@

assertEventName(eventName);
getListeners(this, eventName).add(listener);
let set = getListeners(this, eventName);
if (!set) {
set = new Set();
const events = eventsMap.get(this);
events.set(eventName, set);
}
set.add(listener);
this.logIfDebugEnabled('subscribe', eventName, undefined);

@@ -286,3 +309,10 @@

assertEventName(eventName);
getListeners(this, eventName).delete(listener);
const set = getListeners(this, eventName);
if (set) {
set.delete(listener);
if (set.size === 0) {
const events = eventsMap.get(this);
events.delete(eventName);
}
}

@@ -331,3 +361,3 @@ this.logIfDebugEnabled('unsubscribe', eventName, undefined);

const listeners = getListeners(this, eventName);
const listeners = getListeners(this, eventName) || new Set();
const anyListeners = anyMap.get(this);

@@ -361,3 +391,3 @@ const staticListeners = [...listeners];

const listeners = getListeners(this, eventName);
const listeners = getListeners(this, eventName) || new Set();
const anyListeners = anyMap.get(this);

@@ -413,19 +443,24 @@ const staticListeners = [...listeners];

if (typeof eventName === 'string' || typeof eventName === 'symbol' || typeof eventName === 'number') {
getListeners(this, eventName).clear();
const set = getListeners(this, eventName);
if (set) {
set.clear();
}
const producers = getEventProducers(this, eventName);
if (producers) {
for (const producer of producers) {
producer.finish();
}
for (const producer of producers) {
producer.finish();
producers.clear();
}
producers.clear();
} else {
anyMap.get(this).clear();
for (const listeners of eventsMap.get(this).values()) {
for (const [eventName, listeners] of eventsMap.get(this).entries()) {
listeners.clear();
eventsMap.get(this).delete(eventName);
}
for (const producers of producersMap.get(this).values()) {
for (const [eventName, producers] of producersMap.get(this).entries()) {
for (const producer of producers) {

@@ -436,2 +471,3 @@ producer.finish();

producers.clear();
producersMap.get(this).delete(eventName);
}

@@ -448,4 +484,4 @@ }

if (typeof eventName === 'string') {
count += anyMap.get(this).size + getListeners(this, eventName).size +
getEventProducers(this, eventName).size + getEventProducers(this).size;
count += anyMap.get(this).size + (getListeners(this, eventName) || new Set()).size +
(getEventProducers(this, eventName) || new Set()).size + (getEventProducers(this) || new Set()).size;
continue;

@@ -452,0 +488,0 @@ }

{
"name": "emittery",
"version": "0.12.1",
"version": "0.13.0",
"description": "Simple and modern async event emitter",

@@ -5,0 +5,0 @@ "license": "MIT",

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