Skip to content

Commit cf4177a

Browse files
Invalidate child store subscriptions (#3646)
* Cut off firehose when core is invalid. * wip --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent 23eb5ac commit cf4177a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Examples/Integration/Integration/iOS 17/ObservableSharedStateTestCase.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ private struct Feature {
112112
defaults.removeObject(forKey: "isOn")
113113
}
114114
case .resetButtonTapped:
115-
state.isAppStorageOn1 = false
116-
state.isAppStorageOn2 = false
117-
state.fileStorage1.isOn = false
118-
state.fileStorage2.isOn = false
119-
state.isInMemoryOn1 = false
120-
state.isInMemoryOn2 = false
115+
state.$isAppStorageOn1.withLock { $0 = false }
116+
state.$isAppStorageOn2.withLock { $0 = false }
117+
state.$fileStorage1.withLock { $0.isOn = false }
118+
state.$fileStorage2.withLock { $0.isOn = false }
119+
state.$isInMemoryOn1.withLock { $0 = false }
120+
state.$isInMemoryOn2.withLock { $0 = false }
121121
return .none
122122
case .writeToFileStorageButtonTapped:
123123
return .run { [isOn = state.fileStorage1.isOn] _ in

Sources/ComposableArchitecture/Store.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ public final class Store<State, Action> {
371371

372372
if let stateType = State.self as? any ObservableState.Type {
373373
func subscribeToDidSet<T: ObservableState>(_ type: T.Type) -> AnyCancellable {
374-
core.didSet
374+
return core.didSet
375+
.prefix { [weak self] _ in self?.core.isInvalid != true }
375376
.compactMap { [weak self] in (self?.currentState as? T)?._$id }
376377
.removeDuplicates()
377378
.dropFirst()

Tests/ComposableArchitectureTests/StorePerceptionTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class StorePerceptionTests: BaseTCATestCase {
3232
}
3333

3434
@MainActor
35+
@available(*, deprecated)
3536
func testPerceptionCheck_AccessStateWithoutTracking() {
3637
@MainActor
3738
struct FeatureView: View {

0 commit comments

Comments
 (0)