maplibre-gl-layer-control 0.8.0 → 0.8.1

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/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ class CustomLayerRegistry {
5
5
  constructor() {
6
6
  __publicField(this, "adapters", /* @__PURE__ */ new Map());
7
7
  __publicField(this, "changeListeners", []);
8
- __publicField(this, "unsubscribers", []);
8
+ __publicField(this, "unsubscribers", /* @__PURE__ */ new Map());
9
9
  }
10
10
  /**
11
11
  * Register a custom layer adapter.
@@ -17,7 +17,7 @@ class CustomLayerRegistry {
17
17
  const unsubscribe = adapter.onLayerChange((event, layerId) => {
18
18
  this.notifyChange(event, layerId);
19
19
  });
20
- this.unsubscribers.push(unsubscribe);
20
+ this.unsubscribers.set(adapter.type, unsubscribe);
21
21
  }
22
22
  }
23
23
  /**
@@ -25,6 +25,11 @@ class CustomLayerRegistry {
25
25
  * @param type The adapter type to unregister
26
26
  */
27
27
  unregister(type) {
28
+ const unsubscribe = this.unsubscribers.get(type);
29
+ if (unsubscribe) {
30
+ unsubscribe();
31
+ this.unsubscribers.delete(type);
32
+ }
28
33
  this.adapters.delete(type);
29
34
  }
30
35
  /**
@@ -135,7 +140,7 @@ class CustomLayerRegistry {
135
140
  */
136
141
  destroy() {
137
142
  this.unsubscribers.forEach((unsub) => unsub());
138
- this.unsubscribers = [];
143
+ this.unsubscribers.clear();
139
144
  this.adapters.clear();
140
145
  this.changeListeners = [];
141
146
  }