mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
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:
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.callbacks.push(callback);
|
||||||
this.refCount += 1;
|
this.refCount += 1;
|
||||||
return () => {
|
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;
|
this.refCount -= 1;
|
||||||
if (this.refCount === 0) {
|
if (this.refCount === 0) {
|
||||||
clearInterval(this.interval);
|
clearInterval(this.interval);
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ class ExportLocaleStore {
|
|||||||
}
|
}
|
||||||
cacheEntry.callbacks.push(callback);
|
cacheEntry.callbacks.push(callback);
|
||||||
return () => {
|
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);
|
cacheEntry.callbacks.push(callback);
|
||||||
return () => {
|
return () => {
|
||||||
cacheEntry.callbacks.splice(cacheEntry.callbacks.indexOf(callback), 1);
|
const index = cacheEntry.callbacks.indexOf(callback);
|
||||||
|
if (index !== -1) {
|
||||||
|
cacheEntry.callbacks.splice(index, 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user