MCPcopy
hub / github.com/coder/mux / syncWorkspaces

Method syncWorkspaces

src/browser/stores/WorkspaceStore.ts:3840–3865  ·  view source on GitHub ↗

* Sync workspaces with metadata - add new, remove deleted.

(workspaceMetadata: Map<string, FrontendWorkspaceMetadata>)

Source from the content-addressed store, hash-verified

3838 * Sync workspaces with metadata - add new, remove deleted.
3839 */
3840 syncWorkspaces(workspaceMetadata: Map<string, FrontendWorkspaceMetadata>): void {
3841 const metadataIds = new Set(Array.from(workspaceMetadata.values()).map((m) => m.id));
3842 const currentIds = new Set(this.workspaceMetadata.keys());
3843
3844 // Add new workspaces
3845 for (const metadata of workspaceMetadata.values()) {
3846 if (!currentIds.has(metadata.id)) {
3847 this.addWorkspace(metadata);
3848 }
3849 }
3850
3851 // Remove deleted workspaces
3852 for (const workspaceId of currentIds) {
3853 if (!metadataIds.has(workspaceId)) {
3854 this.removeWorkspace(workspaceId);
3855 }
3856 }
3857
3858 // Re-evaluate the active subscription after additions/removals.
3859 // removeWorkspace can null activeWorkspaceId when the removed workspace
3860 // was active (e.g., stale singleton state between integration tests),
3861 // leaving addWorkspace's ensureActiveOnChatSubscription targeting the
3862 // old workspace. This final call reconciles the subscription with the
3863 // current activeWorkspaceId + registration state.
3864 this.ensureActiveOnChatSubscription();
3865 }
3866
3867 /**
3868 * Cleanup all subscriptions (call on unmount).

Callers

nothing calls this directly

Calls 4

addWorkspaceMethod · 0.95
removeWorkspaceMethod · 0.95
hasMethod · 0.45

Tested by

no test coverage detected