From c64b6845bdec716a413b7c8878d577dad45fd211 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 29 Nov 2023 15:47:20 -0800 Subject: [PATCH] Revert "Return "invalid" stores from scoping (#2601)" This reverts commit ff276875c4fdfff0d7e0aa4812c2423b994db56b. This introduced a regression in our examples, so we should revisit in a new PR with more test coverage. --- Sources/ComposableArchitecture/Store.swift | 23 ++++------------------ 1 file changed, 4 insertions(+), 19 deletions(-) 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