Skip to content

Commit

Permalink
added observation compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bpisano committed May 25, 2024
1 parent fdb6dbf commit 5ec93de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 12 additions & 4 deletions Sources/StateKit/StateValidator/StateValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyCancellable> = []
@ObservationIgnored private let initialState: _State
@ObservationIgnored private let validators: [AnyValidator<_State>]
@ObservationIgnored private var cancellableSubscribers: Set<AnyCancellable> = []

public init(
initialState: _State,
@ValidatorBuilder<_State> _ validators: () -> [AnyValidator<_State>]) {
self.currentState = initialState
self.currentStatePublisher = .init(initialState)
self.initialState = initialState
self.validators = validators()
observeValidators()
Expand Down

0 comments on commit 5ec93de

Please sign in to comment.