Skip to content

refactor(events): drop four 1-to-1 PassthroughSubject buses for direct ownership#1150

Merged
datlechin merged 1 commit into
mainfrom
refactor/drop-1to1-event-buses
May 9, 2026
Merged

refactor(events): drop four 1-to-1 PassthroughSubject buses for direct ownership#1150
datlechin merged 1 commit into
mainfrom
refactor/drop-1to1-event-buses

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

Four publishers on AppCommands had a single sender and a single receiver where direct ownership was already available. They are removed:

  • saveAsFavoriteRequestedMainContentCoordinator+Favorites sent it, MainEditorContentView received it inside the same coordinator graph. Replaced with an @Observable favoriteDialogQuery: FavoriteDialogQuery? on the coordinator. The view binds the sheet's item: to it via Binding(get:set:).
  • focusConnectionFormWindowRequested — sent in WelcomeViewModel.focusConnectionFormWindow(), received in AppDelegate.handleFocusConnectionForm(). The lookup (NSApp.windows.first(where: AppLaunchCoordinator.isConnectionFormWindow) → makeKeyAndOrderFront) is now inlined directly in WelcomeViewModel.
  • openSampleDatabaseRequested — sent from the File menu, received in AppDelegate which just called SampleDatabaseLauncher.open(). Now the menu calls SampleDatabaseLauncher.open() directly.
  • resetSampleDatabaseRequested — same shape, now calls SampleDatabaseLauncher.reset() directly.

Side effects:

  • AppDelegate.handleFocusConnectionForm and the commandCancellables set are removed (no remaining subscribers).
  • AppCommands.swift shrinks by four publisher declarations.

exportConnections, importConnections, importConnectionsFromApp (also flagged by the audit) are left in place: the menu fires regardless of whether the welcome view is loaded, so the publisher is genuinely 1-to-N (1-or-0 receivers depending on welcome window state) and benefits from the bus's auto-no-op-when-no-subscriber semantics.

Why this matters

This is audit finding 4.1, partial. Direct ownership is the stronger pattern when the receiver is reachable: it removes hidden subscribers, makes the call graph traceable in Xcode (jump-to-definition lands on the implementation, not on the publisher), and keeps AppCommands reserved for genuine fan-out.

Test plan

  • Save current query as favorite via Cmd+D / menu and confirm the dialog still appears.
  • Save selection-as-favorite from the editor context menu.
  • Open and reset the sample database via the File menu.
  • Use a welcome action that focuses the existing connection form window.
  • swiftlint --strict clean on changed files.

@datlechin datlechin merged commit aa8cf30 into main May 9, 2026
2 checks passed
@datlechin datlechin deleted the refactor/drop-1to1-event-buses branch May 9, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant