From b3dc262862652820c7289f163712aa353bca1a85 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 19 Mar 2026 16:10:54 +0100 Subject: [PATCH] Remove error prone refCount logic This can simply use the length of the callbacks array instead. --- packages/web_ui/src/store/default_mod_pack_store.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/web_ui/src/store/default_mod_pack_store.ts b/packages/web_ui/src/store/default_mod_pack_store.ts index bd4686fd..d7d88184 100644 --- a/packages/web_ui/src/store/default_mod_pack_store.ts +++ b/packages/web_ui/src/store/default_mod_pack_store.ts @@ -3,7 +3,6 @@ import type { Control } from "../util/websocket"; // TODO: replace this super duper expensive method with listening to a default mod pack id event. class DefaultModPackStore { - refCount = 0; interval: undefined | ReturnType; modPack: undefined | ModPack; callbacks: (() => void)[] = []; @@ -27,20 +26,18 @@ class DefaultModPackStore { } subscribe(control: Control, callback: () => void) { - if (this.refCount === 0) { + if (this.callbacks.length === 0) { const update = () => { this.fetchDefaultModPack(control); }; update(); this.interval = setInterval(update, 60e3); } this.callbacks.push(callback); - this.refCount += 1; return () => { const index = this.callbacks.indexOf(callback); if (index !== -1) { this.callbacks.splice(index, 1); } - this.refCount -= 1; - if (this.refCount === 0) { + if (this.callbacks.length === 0) { clearInterval(this.interval); this.interval = undefined; }