2024-03-28 23:01:06 -05:00

31 lines
876 B
Swift

import Combine
import Foundation
/// A processor is responsible for receiving and processing dispatched actions. Generally a
/// processor will mutate local state based on the action it receives.
///
@MainActor
public protocol Processor: AnyObject, Sendable {
associatedtype State: Sendable
associatedtype Action: Sendable
associatedtype Effect: Sendable
/// The processor's current state.
var state: State { get }
/// A publisher that publishes the processor's state when it changes.
var statePublisher: AnyPublisher<State, Never> { get }
/// Performs an asynchronous effect.
///
/// - Parameter effect: The effect to perform.
///
func perform(_ effect: Effect) async
/// Receives an action from the view's store.
///
/// - Parameter action: The action to process.
///
func receive(_ action: Action)
}