diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index 18595a048c54..897e6315ec86 100644 --- a/Sources/ComposableArchitecture/Store.swift +++ b/Sources/ComposableArchitecture/Store.swift @@ -139,7 +139,7 @@ public final class Store { private var isSending = false var parentCancellable: AnyCancellable? private let reducer: any Reducer - @_spi(Internals) public var stateSubject: CurrentValueSubject! + @_spi(Internals) public var stateSubject: CurrentValueSubject #if DEBUG private let mainThreadChecksEnabled: Bool #endif @@ -175,14 +175,6 @@ public final class Store { } } - fileprivate init() { - self._isInvalidated = { true } - self.reducer = EmptyReducer() - #if DEBUG - self.mainThreadChecksEnabled = true - #endif - } - deinit { self.invalidate() Logger.shared.log("\(storeTypeName(of: self)).deinit") @@ -1002,15 +994,12 @@ private final class ScopedStoreReducer: Re @inlinable func reduce(into state: inout State, action: Action) -> Effect { - let isInvalid = self.isInvalid() - if isInvalid { + if self.isInvalid() { self.onInvalidate() } self.isSending = true defer { - if !isInvalid || state is _OptionalProtocol { - state = self.toState(self.rootStore.stateSubject.value) - } + state = self.toState(self.rootStore.stateSubject.value) self.isSending = false } if let action = self.fromAction(action), @@ -1043,10 +1032,6 @@ extension ScopedStoreReducer: AnyScopedStoreReducer { isInvalid: ((S) -> Bool)?, removeDuplicates isDuplicate: ((ChildState, ChildState) -> Bool)? ) -> Store { - guard isInvalid.map({ $0(store.stateSubject.value) == false }) ?? true - else { - return Store() - } let id = id?(store.stateSubject.value) if let id = id, let childStore = store.children[id] as? Store @@ -1068,7 +1053,7 @@ extension ScopedStoreReducer: AnyScopedStoreReducer { } let reducer = ScopedStoreReducer( rootStore: self.rootStore, - state: { [stateSubject = store.stateSubject!] _ in toChildState(stateSubject.value) }, + state: { [stateSubject = store.stateSubject] _ in toChildState(stateSubject.value) }, action: { fromChildAction($0).flatMap(fromAction) }, isInvalid: isInvalid, onInvalidate: { [weak store] in