Skip to content

Commit

Permalink
fix: connection status map wrapped in atom (#1783)
Browse files Browse the repository at this point in the history
This wraps the connection status map in an atom so it properly updates
when an individual connection status changes.
  • Loading branch information
oneirocosm authored Jan 21, 2025
1 parent 4fba9e6 commit 8a853de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frontend/app/store/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let atoms: GlobalAtomsType;
let globalEnvironment: "electron" | "renderer";
const blockComponentModelMap = new Map<string, BlockComponentModel>();
const Counters = new Map<string, number>();
const ConnStatusMap = new Map<string, PrimitiveAtom<ConnStatus>>();
const ConnStatusMapAtom = atom(new Map<string, PrimitiveAtom<ConnStatus>>());

type GlobalInitOptions = {
tabId: string;
Expand Down Expand Up @@ -135,7 +135,8 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
const typeAheadModalAtom = atom({});
const modalOpen = atom(false);
const allConnStatusAtom = atom<ConnStatus[]>((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<FlashErrorType[]>([]);
Expand Down Expand Up @@ -579,7 +580,8 @@ function subscribeToConnEvents() {
}

function getConnStatusAtom(conn: string): PrimitiveAtom<ConnStatus> {
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
Expand All @@ -605,7 +607,9 @@ function getConnStatusAtom(conn: string): PrimitiveAtom<ConnStatus> {
};
rtn = atom(connStatus);
}
ConnStatusMap.set(conn, rtn);
const newConnStatusMap = new Map(connStatusMap);
newConnStatusMap.set(conn, rtn);
globalStore.set(ConnStatusMapAtom, newConnStatusMap);
}
return rtn;
}
Expand Down

0 comments on commit 8a853de

Please sign in to comment.