Skip to content

Replace closure-based event bus with delegate protocol #142

@dhilgaertner

Description

@dhilgaertner

Problem

AppState has 15+ optional closure properties (onDeleteSession, onCompleteSession, onAddTerminal, onLaunchClaude, etc.) wired in AppDelegate via weak captures (lines 136–221). This pattern is fragile: closures silently no-op if the captured service deallocates, there's no compile-time guarantee that all callbacks are wired, and the wiring is scattered across 80+ lines of boilerplate.

Proposed Improvement

Define a SessionActionDelegate protocol with required methods. AppDelegate (or a coordinator) conforms to it. AppState holds a single weak delegate reference instead of 15 optional closures. This gives compile-time safety and eliminates the wiring boilerplate.

Effort

Medium (2–3 hours). Mechanical transformation — define protocol, conform, replace closure calls with delegate calls.

Files Affected

  • Packages/CrowCore/Sources/CrowCore/AppState.swift (remove 15+ closure properties)
  • Sources/Crow/App/AppDelegate.swift (replace wiring with single delegate assignment)
  • Packages/CrowUI/Sources/CrowUI/*.swift (views call delegate methods instead of closures)
  • New: Packages/CrowCore/Sources/CrowCore/SessionActionDelegate.swift

Priority: 5/10

Metadata

Metadata

Assignees

Labels

refactorCode refactoring and cleanup

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions