refactor: group applyMountedChange callbacks under a single field
Code review on pr-735 flagged `applyMountedChange` for exceeding the 8-parameter limit. The three effect callbacks (`onSetDefaultWorkspace`, `onSwitchVault`, `onUpdateWorkspaceIdentity`) are now grouped under a single `callbacks` field. The function's destructure surface drops from 8 to 6 fields, and the semantic split between "state + change" and "effects" is now explicit in the type. No behaviour change; the six existing tests pass unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,10 +23,8 @@ function callApply(overrides: ChangeOverrides) {
|
||||
vaultPath: overrides.vaultPath ?? '/a',
|
||||
includedVaults: overrides.includedVaults ?? [vault('/a'), vault('/b')],
|
||||
mounted: overrides.mounted ?? false,
|
||||
onSetDefaultWorkspace,
|
||||
onSwitchVault,
|
||||
onUpdateWorkspaceIdentity,
|
||||
path: overrides.path ?? '/a',
|
||||
callbacks: { onSetDefaultWorkspace, onSwitchVault, onUpdateWorkspaceIdentity },
|
||||
})
|
||||
return { onSetDefaultWorkspace, onSwitchVault, onUpdateWorkspaceIdentity }
|
||||
}
|
||||
|
||||
@@ -356,13 +356,15 @@ function useVaultMenuInteractions({
|
||||
const handleMountedChange = useCallback((path: string, mounted: boolean) => {
|
||||
applyMountedChange({
|
||||
defaultPath,
|
||||
vaultPath,
|
||||
includedVaults,
|
||||
mounted,
|
||||
onSetDefaultWorkspace,
|
||||
onSwitchVault,
|
||||
onUpdateWorkspaceIdentity,
|
||||
path,
|
||||
vaultPath,
|
||||
callbacks: {
|
||||
onSetDefaultWorkspace,
|
||||
onSwitchVault,
|
||||
onUpdateWorkspaceIdentity,
|
||||
},
|
||||
})
|
||||
}, [defaultPath, includedVaults, onSetDefaultWorkspace, onSwitchVault, onUpdateWorkspaceIdentity, vaultPath])
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import type { VaultOption } from './types'
|
||||
|
||||
export interface VaultMountChangeRequest {
|
||||
defaultPath: string
|
||||
includedVaults: VaultOption[]
|
||||
mounted: boolean
|
||||
export interface VaultMountChangeCallbacks {
|
||||
onSetDefaultWorkspace?: (path: string) => void
|
||||
onSwitchVault: (path: string) => void
|
||||
onUpdateWorkspaceIdentity?: (path: string, patch: Partial<VaultOption>) => void
|
||||
path: string
|
||||
}
|
||||
|
||||
export interface VaultMountChangeRequest {
|
||||
defaultPath: string
|
||||
vaultPath: string
|
||||
includedVaults: VaultOption[]
|
||||
mounted: boolean
|
||||
path: string
|
||||
callbacks: VaultMountChangeCallbacks
|
||||
}
|
||||
|
||||
function nextIncludedVaultPath(includedVaults: VaultOption[], currentPath: string): string | null {
|
||||
@@ -17,19 +21,17 @@ function nextIncludedVaultPath(includedVaults: VaultOption[], currentPath: strin
|
||||
|
||||
export function applyMountedChange({
|
||||
defaultPath,
|
||||
vaultPath,
|
||||
includedVaults,
|
||||
mounted,
|
||||
onSetDefaultWorkspace,
|
||||
onSwitchVault,
|
||||
onUpdateWorkspaceIdentity,
|
||||
path,
|
||||
vaultPath,
|
||||
callbacks,
|
||||
}: VaultMountChangeRequest): void {
|
||||
if (!mounted && (path === defaultPath || path === vaultPath)) {
|
||||
const nextPath = nextIncludedVaultPath(includedVaults, path)
|
||||
if (!nextPath) return
|
||||
if (path === defaultPath) onSetDefaultWorkspace?.(nextPath)
|
||||
if (path === vaultPath) onSwitchVault(nextPath)
|
||||
if (path === defaultPath) callbacks.onSetDefaultWorkspace?.(nextPath)
|
||||
if (path === vaultPath) callbacks.onSwitchVault(nextPath)
|
||||
}
|
||||
onUpdateWorkspaceIdentity?.(path, { mounted })
|
||||
callbacks.onUpdateWorkspaceIdentity?.(path, { mounted })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user