1.8 KiB
1.8 KiB
Store (Zustand)
State management with slices pattern for domain organization.
Structure
index.ts- Store creation, combines all slicestypes.ts- AppState type definitionslices/- Individual domain slicesutils/- Store utilities (paneHelpers.ts,pathResolution.ts)
Slices (12 total)
| Slice | Purpose |
|---|---|
projectSlice |
Projects list, selectedProjectId |
repositorySlice |
Repository grouping, worktrees |
sessionSlice |
Sessions list, pagination, selectedSessionId |
sessionDetailSlice |
Session detail, chunks, metrics |
subagentSlice |
Subagent data, selectedSubagentId |
conversationSlice |
Messages, conversation metadata |
tabSlice |
Tabs list, activeTabId, tab ordering |
tabUISlice |
Per-tab UI state (expansions, scroll) |
paneSlice |
Pane layout, split views |
uiSlice |
UI flags (sidebar visible, etc.) |
notificationSlice |
Notifications, unreadCount |
configSlice |
App config, triggers |
Slice Pattern
Each slice follows:
data: T[]
selectedId: string | null
loading: boolean
error: string | null
Key Pattern: Per-Tab UI Isolation
tabUISlice maintains independent UI state per tab using tabId:
expandedAIGroupIds,expandedDisplayItemIds,expandedSubagentTraceIds- Ensures expanding a group in tab A doesn't affect tab B
Store Initialization
Call initializeNotificationListeners() once in App.tsx useEffect:
- Subscribes to file change events
- Auto-refreshes sessions on new files
- Updates session detail on content change
- Uses
refreshSessionInPlaceto prevent flickering
Adding a Slice
- Create
slices/{domain}Slice.ts - Export
create{Domain}Slicefunction - Add to store composition in
index.ts - Update
AppStatetype intypes.ts