-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: connection status map wrapped in atom #1783
Conversation
This wraps the connection status map in an atom so it properly updates when an individual connection status changes.
WalkthroughThe pull request introduces a significant change in connection status management within the global state of the frontend application. The modification transitions from using a direct This change fundamentally alters how connection status data is managed, moving from a mutable data structure to a reactive atom-based approach. The new implementation creates a Jotai atom that holds a The update impacts how connection statuses are retrieved, created, and stored, with the core logic now centered around manipulating the new ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
frontend/app/store/global.ts (1)
26-26
: Consider usingatomFamily
for managing connection statusesCurrently,
ConnStatusMapAtom
wraps a mutableMap
within an atom. While you clone theMap
before updates to maintain immutability, this can become inefficient as the number of connections grows. UtilizingatomFamily
from Jotai allows you to create atoms dynamically keyed by connection names, simplifying state management and enhancing performance by avoiding the need to clone the entireMap
.To implement this, you can define an
atomFamily
for connection statuses:import { atomFamily } from 'jotai/utils'; const connStatusAtomFamily = atomFamily((conn: string) => atom<ConnStatus>({ connection: conn, connected: false, error: null, status: "disconnected", hasconnected: false, activeconnnum: 0, wshenabled: false, }) );Then, adjust your
getConnStatusAtom
function to useconnStatusAtomFamily
:-function getConnStatusAtom(conn: string): PrimitiveAtom<ConnStatus> { - const connStatusMap = globalStore.get(ConnStatusMapAtom); - let rtn = connStatusMap.get(conn); - if (rtn == null) { - // ...initialize rtn... - const newConnStatusMap = new Map(connStatusMap); - newConnStatusMap.set(conn, rtn); - globalStore.set(ConnStatusMapAtom, newConnStatusMap); - } - return rtn; +function getConnStatusAtom(conn: string): PrimitiveAtom<ConnStatus> { + return connStatusAtomFamily(conn); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/app/store/global.ts
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build for TestDriver.ai
🔇 Additional comments (1)
frontend/app/store/global.ts (1)
Line range hint
583-612
: Avoid cloning the entireMap
on each updateIn the
getConnStatusAtom
function, cloning theconnStatusMap
whenever a new connection is added can lead to performance issues as the number of connections increases. This concern is addressed by the previous suggestion to useatomFamily
, which eliminates the need to manage aMap
and clone it on every update.
This wraps the connection status map in an atom so it properly updates when an individual connection status changes.