Skip to content

Commit

Permalink
Revert "Return "invalid" stores from scoping (#2601)"
Browse files Browse the repository at this point in the history
This reverts commit ff27687.

This introduced a regression in our examples, so we should revisit in a
new PR with more test coverage.
  • Loading branch information
stephencelis committed Nov 29, 2023
1 parent ff27687 commit c64b684
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public final class Store<State, Action> {
private var isSending = false
var parentCancellable: AnyCancellable?
private let reducer: any Reducer<State, Action>
@_spi(Internals) public var stateSubject: CurrentValueSubject<State, Never>!
@_spi(Internals) public var stateSubject: CurrentValueSubject<State, Never>
#if DEBUG
private let mainThreadChecksEnabled: Bool
#endif
Expand Down Expand Up @@ -175,14 +175,6 @@ public final class Store<State, Action> {
}
}

fileprivate init() {
self._isInvalidated = { true }
self.reducer = EmptyReducer()
#if DEBUG
self.mainThreadChecksEnabled = true
#endif
}

deinit {
self.invalidate()
Logger.shared.log("\(storeTypeName(of: self)).deinit")
Expand Down Expand Up @@ -1002,15 +994,12 @@ private final class ScopedStoreReducer<RootState, RootAction, State, Action>: Re

@inlinable
func reduce(into state: inout State, action: Action) -> Effect<Action> {
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),
Expand Down Expand Up @@ -1043,10 +1032,6 @@ extension ScopedStoreReducer: AnyScopedStoreReducer {
isInvalid: ((S) -> Bool)?,
removeDuplicates isDuplicate: ((ChildState, ChildState) -> Bool)?
) -> Store<ChildState, ChildAction> {
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<ChildState, ChildAction>
Expand All @@ -1068,7 +1053,7 @@ extension ScopedStoreReducer: AnyScopedStoreReducer {
}
let reducer = ScopedStoreReducer<RootState, RootAction, ChildState, ChildAction>(
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
Expand Down

0 comments on commit c64b684

Please sign in to comment.