diff --git a/Sources/Flow/ActionHandler/ActionHandler.swift b/Sources/Flow/ActionHandler/ActionHandler.swift index cd4e3c1..5305e3b 100644 --- a/Sources/Flow/ActionHandler/ActionHandler.swift +++ b/Sources/Flow/ActionHandler/ActionHandler.swift @@ -119,7 +119,17 @@ import Foundation /// /// The Facade pattern here is a feature, not a code smell. It provides clean abstraction /// and hides implementation complexity from users while maintaining full testability. -public final class ActionHandler { +/// +/// ## Type Constraints +/// +/// Type parameters are constrained to match Feature protocol requirements: +/// - `Action: Sendable` ensures safe concurrent action dispatching +/// - `State: AnyObject` ensures reference semantics for direct state mutation +/// - `ActionResult: Sendable` ensures safe concurrent result handling +/// +/// These constraints prevent common errors like using value-type State (which wouldn't +/// support mutation) or non-Sendable actions (which could cause data races). +public final class ActionHandler { private let processor: ActionProcessor /// Creates a ActionHandler with the given action processing logic. diff --git a/Sources/Flow/ActionHandler/ActionProcessor.swift b/Sources/Flow/ActionHandler/ActionProcessor.swift index b89795c..645c840 100644 --- a/Sources/Flow/ActionHandler/ActionProcessor.swift +++ b/Sources/Flow/ActionHandler/ActionProcessor.swift @@ -1,7 +1,9 @@ import Foundation /// Action execution closure that mutates state and returns a task. -public typealias ActionExecution = +/// +/// - Note: Type constraints match Feature protocol requirements to ensure consistency. +public typealias ActionExecution = @MainActor (Action, State) async -> ActionTask @@ -25,7 +27,12 @@ public typealias StateErrorHandler = (Error, State) -> Void /// .use(LoggingMiddleware()) /// .onError { error, state in state.errorMessage = "\(error)" } /// ``` -public final class ActionProcessor { +/// +/// - Note: Type constraints match Feature protocol requirements: +/// - `Action: Sendable` for safe concurrency across tasks +/// - `State: AnyObject` ensures reference semantics for state mutation +/// - `ActionResult: Sendable` for safe concurrency of operation results +public final class ActionProcessor { private let baseExecution: ActionExecution private let errorHandler: StateErrorHandler? private let middlewareManager: MiddlewareManager