From 8a853ded56a502824ac134085e54cb057efb3187 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:45:45 -0800 Subject: [PATCH] fix: connection status map wrapped in atom (#1783) This wraps the connection status map in an atom so it properly updates when an individual connection status changes. --- frontend/app/store/global.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index c8a7daae2..e80c3e7bc 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -23,7 +23,7 @@ let atoms: GlobalAtomsType; let globalEnvironment: "electron" | "renderer"; const blockComponentModelMap = new Map(); const Counters = new Map(); -const ConnStatusMap = new Map>(); +const ConnStatusMapAtom = atom(new Map>()); type GlobalInitOptions = { tabId: string; @@ -135,7 +135,8 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) { const typeAheadModalAtom = atom({}); const modalOpen = atom(false); const allConnStatusAtom = atom((get) => { - const connStatuses = Array.from(ConnStatusMap.values()).map((atom) => get(atom)); + const connStatusMap = get(ConnStatusMapAtom); + const connStatuses = Array.from(connStatusMap.values()).map((atom) => get(atom)); return connStatuses; }); const flashErrorsAtom = atom([]); @@ -579,7 +580,8 @@ function subscribeToConnEvents() { } function getConnStatusAtom(conn: string): PrimitiveAtom { - let rtn = ConnStatusMap.get(conn); + const connStatusMap = globalStore.get(ConnStatusMapAtom); + let rtn = connStatusMap.get(conn); if (rtn == null) { if (isBlank(conn)) { // create a fake "local" status atom that's always connected @@ -605,7 +607,9 @@ function getConnStatusAtom(conn: string): PrimitiveAtom { }; rtn = atom(connStatus); } - ConnStatusMap.set(conn, rtn); + const newConnStatusMap = new Map(connStatusMap); + newConnStatusMap.set(conn, rtn); + globalStore.set(ConnStatusMapAtom, newConnStatusMap); } return rtn; }