Skip to content

Centralize duplicate AppState + Store mutation pattern #145

@dhilgaertner

Description

@dhilgaertner

Problem

Every RPC handler and service method that modifies state follows the same two-step pattern: mutate appState property, then call store.mutate { ... } with a near-identical mutation. This is duplicated 20+ times in AppDelegate's RPC handlers and throughout SessionService. It's easy to update one and forget the other, leading to state/persistence divergence.

Proposed Improvement

Create mutation methods on a thin service layer (or extend SessionService) that atomically update both AppState and JSONStore. For example: func updateSession(id: UUID, mutate: (inout Session) -> Void) that applies the change to both stores in one call.

Effort

Medium (2–3 hours). Define the helper methods, replace dual-mutation call sites.

Files Affected

  • Sources/Crow/App/AppDelegate.swift (20+ dual-mutation sites in RPC handlers)
  • Sources/Crow/App/SessionService.swift
  • Potentially new: Sources/Crow/App/StateMutator.swift

Priority: 8/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