refactor(frontend): extract useSessionListStreams from App.vue - #318
Merged
Conversation
Seventh slice of milestone 5-a. App.vue carried three module-scope transport handles for the session lists: let localSessionListConn: SessionListConnection | null = null; let remoteSessionListConn: SessionListConnection | null = null; let remotePollHandle: number | null = null; Every attach/replace had to detach the old handle first, and the remote side had two competing transports (WS + HTTP poll) that had to be mutually exclusive. That policy was open-coded across six sites (connectLocalSessionList, connectRemoteSessionListWS, stopRemotePoll, startPlatformRemotePoll, connectRemoteSessionList, and the web-boot catch block that fell back to polling on error) — each one manually calling `?.detach()` + `clearInterval` + reassigning the module handle. Pull the three handles + the transport policy into composables/useSessionListStreams.ts, exposing: attachLocal(endpoint, callbacks) attachRemoteWS(endpoint, callbacks) // stops any active poll first startRemotePoll(fn, intervalMs) // stops any active WS first stopRemote() // detach WS + clear poll isRemoteWSAttached() // for startPlatformRemotePoll gate detachAll() // onUnmounted cleanup The composable is purely the transport layer — all app-level state (list refs, endpoint refs, missingSince map, config dedup key, apply / prune functions) stays with the caller. The WS <-> poll mutex is now enforced by construction: startRemotePoll always calls stopRemote first, attachRemoteWS too. App.vue side: - Drop the three module-scope handles. - Drop the standalone stopRemotePoll() helper (was 8 lines). - Drop the SessionListConnection import. - Every attach/detach site collapses to one composable method call. - startPlatformRemotePoll's "is WS already up?" check moves from a `remoteSessionListConn` module-var peek to `sessionListStreams.isRemoteWSAttached()`. Net: App.vue -32 / +15; new composable +108. `npm test` 1631 pass; `npm run build` green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Seventh slice of milestone 5-a. App.vue carried three module-scope transport handles for the session lists:
```ts
let localSessionListConn: SessionListConnection | null = null;
let remoteSessionListConn: SessionListConnection | null = null;
let remotePollHandle: number | null = null;
```
Every attach/replace had to detach the old handle first, and the remote side had two competing transports (WS + HTTP poll) that had to be mutually exclusive. That policy was open-coded across six sites (`connectLocalSessionList`, `connectRemoteSessionListWS`, `stopRemotePoll`, `startPlatformRemotePoll`, `connectRemoteSessionList`, and the web-boot catch block that fell back to polling on error) — each one manually calling `?.detach()` + `clearInterval` + reassigning the module handle.
Pull the three handles + the transport policy into `composables/useSessionListStreams.ts`, exposing:
```ts
attachLocal(endpoint, callbacks)
attachRemoteWS(endpoint, callbacks) // stops any active poll first
startRemotePoll(fn, intervalMs) // stops any active WS first
stopRemote() // detach WS + clear poll
isRemoteWSAttached() // for startPlatformRemotePoll gate
detachAll() // onUnmounted cleanup
```
The composable is purely the transport layer — all app-level state (list refs, endpoint refs, `missingSince` map, config dedup key, apply / prune functions) stays with the caller. The WS ↔ poll mutex is now enforced by construction: `startRemotePoll` always calls `stopRemote` first, `attachRemoteWS` too.
App.vue side:
Net: App.vue -32 / +15; new composable +108. App.vue now 1749 lines (was 1766).
Test plan