Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate child store subscriptions #3646

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ private struct Feature {
defaults.removeObject(forKey: "isOn")
}
case .resetButtonTapped:
state.isAppStorageOn1 = false
state.isAppStorageOn2 = false
state.fileStorage1.isOn = false
state.fileStorage2.isOn = false
state.isInMemoryOn1 = false
state.isInMemoryOn2 = false
state.$isAppStorageOn1.withLock { $0 = false }
state.$isAppStorageOn2.withLock { $0 = false }
state.$fileStorage1.withLock { $0.isOn = false }
state.$fileStorage2.withLock { $0.isOn = false }
state.$isInMemoryOn1.withLock { $0 = false }
state.$isInMemoryOn2.withLock { $0 = false }
return .none
case .writeToFileStorageButtonTapped:
return .run { [isOn = state.fileStorage1.isOn] _ in
Expand Down
3 changes: 2 additions & 1 deletion Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ public final class Store<State, Action> {

if let stateType = State.self as? any ObservableState.Type {
func subscribeToDidSet<T: ObservableState>(_ type: T.Type) -> AnyCancellable {
core.didSet
return core.didSet
.prefix { [weak self] _ in self?.core.isInvalid != true }
.compactMap { [weak self] in (self?.currentState as? T)?._$id }
.removeDuplicates()
.dropFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class StorePerceptionTests: BaseTCATestCase {
}

@MainActor
@available(*, deprecated)
func testPerceptionCheck_AccessStateWithoutTracking() {
@MainActor
struct FeatureView: View {
Expand Down