Handle incorrect usage of subscribe in stores

If the unsubscribe function is called multiple times the indexOf
function will return -1 which will end up removing random other
subscription callbacks.  Prevent the incorrect callabck removial
in this case.
This commit is contained in:
Hornwitser committed 2026-03-17 23:23:03 +01:00
1 parent 781b98b1c1
commit d90ac998aa
3 files changed
+12 -3

No files matched your search

@@ -35,7 +35,10 @@ class DefaultModPackStore {
this.callbacks.push(callback);
this.refCount += 1;
return () => {
this.callbacks.splice(this.callbacks.indexOf(callback), 1);
const index = this.callbacks.indexOf(callback);
if (index !== -1) {
this.callbacks.splice(index, 1);
}
this.refCount -= 1;
if (this.refCount === 0) {
clearInterval(this.interval);
@@ -47,7 +47,10 @@ class ExportLocaleStore {
}
cacheEntry.callbacks.push(callback);
return () => {
cacheEntry.callbacks.splice(cacheEntry.callbacks.indexOf(callback), 1);
const index = cacheEntry.callbacks.indexOf(callback);
if (index !== -1) {
cacheEntry.callbacks.splice(index, 1);
}
};
}
@@ -112,7 +112,10 @@ class ExportPrototypeMetadataStore {
}
cacheEntry.callbacks.push(callback);
return () => {
cacheEntry.callbacks.splice(cacheEntry.callbacks.indexOf(callback), 1);
const index = cacheEntry.callbacks.indexOf(callback);
if (index !== -1) {
cacheEntry.callbacks.splice(index, 1);
}
};
}