@mark1russell7/collections 0.9.8 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/collections",
4
- "version": "0.9.8",
4
+ "version": "0.9.9",
5
5
  "description": "Collections with no dependencies: lists, maps, queues, a summary tree, channels, lazy operations and dependency graphs.",
6
6
  "keywords": [
7
7
  "collections",
@@ -71,8 +71,8 @@ export class Emitter<E extends EventMap> {
71
71
  // Return unsubscribe function
72
72
  return () => {
73
73
  listeners!.delete(listener);
74
- // Clean up empty sets
75
- if (listeners!.size === 0) {
74
+ // An off() can replace the set of the event. Remove only the set of this subscription.
75
+ if (listeners!.size === 0 && this.listeners.get(event) === listeners) {
76
76
  this.listeners.delete(event);
77
77
  }
78
78
  };
@@ -265,7 +265,8 @@ export class AsyncEmitter<E extends EventMap> {
265
265
 
266
266
  return () => {
267
267
  listeners!.delete(listener);
268
- if (listeners!.size === 0) {
268
+ // An off() can replace the set of the event. Remove only the set of this subscription.
269
+ if (listeners!.size === 0 && this.listeners.get(event) === listeners) {
269
270
  this.listeners.delete(event);
270
271
  }
271
272
  };