diff --git a/Package.swift b/Package.swift index 97bda70..d8b0dc0 100644 --- a/Package.swift +++ b/Package.swift @@ -6,11 +6,11 @@ import CompilerPluginSupport let package = Package( name: "StateKit", platforms: [ - .iOS(.v13), - .watchOS(.v6), - .tvOS(.v13), - .macCatalyst(.v13), - .macOS(.v10_15) + .iOS(.v17), + .watchOS(.v10), + .tvOS(.v17), + .macCatalyst(.v17), + .macOS(.v14) ], products: [ .library( diff --git a/Sources/StateKit/StateValidator/StateValidator.swift b/Sources/StateKit/StateValidator/StateValidator.swift index 7c73c42..f8f0ec5 100644 --- a/Sources/StateKit/StateValidator/StateValidator.swift +++ b/Sources/StateKit/StateValidator/StateValidator.swift @@ -6,19 +6,27 @@ // import Foundation +import Observation import Combine +@Observable public final class StateValidator<_State: State> { - @Published public var currentState: _State + public var currentState: _State { + didSet { + currentStatePublisher.send(currentState) + } + } + @ObservationIgnored public var currentStatePublisher: CurrentValueSubject<_State, Never> - private let initialState: _State - private let validators: [AnyValidator<_State>] - private var cancellableSubscribers: Set = [] + @ObservationIgnored private let initialState: _State + @ObservationIgnored private let validators: [AnyValidator<_State>] + @ObservationIgnored private var cancellableSubscribers: Set = [] public init( initialState: _State, @ValidatorBuilder<_State> _ validators: () -> [AnyValidator<_State>]) { self.currentState = initialState + self.currentStatePublisher = .init(initialState) self.initialState = initialState self.validators = validators() observeValidators()