Skip to content

Commit da6b134

Browse files
committed
wip
1 parent 24dcb95 commit da6b134

File tree

6 files changed

+44
-24
lines changed

6 files changed

+44
-24
lines changed

Sources/ComposableArchitecture/Core.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ final class RootCore<Root: Reducer>: Core {
6161
self.reducer = reducer
6262
}
6363
func send(_ action: Root.Action) -> Task<Void, Never>? {
64-
_withoutPerceptionChecking {
65-
_send(action)
66-
}
64+
_withoutPerceptionChecking {
65+
_send(action)
66+
}
6767
}
68-
func _send(_ action: Root.Action) -> Task<Void, Never>? {
68+
private func _send(_ action: Root.Action) -> Task<Void, Never>? {
6969
self.bufferedActions.append(action)
7070
guard !self.isSending else { return nil }
7171

Sources/ComposableArchitecture/Internal/NavigationID.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Foundation
12
@_spi(Reflection) import CasePaths
23

34
extension DependencyValues {
@@ -38,8 +39,6 @@ struct NavigationID: Hashable, @unchecked Sendable {
3839
private let identifier: AnyHashable?
3940
private let tag: UInt32?
4041

41-
42-
4342
enum Kind: Hashable {
4443
case casePath(root: Any.Type, value: Any.Type)
4544
case keyPath(AnyKeyPath)
@@ -113,10 +112,10 @@ struct NavigationID: Hashable, @unchecked Sendable {
113112
}
114113
}
115114

116-
init(kind: Kind, identifier: AnyHashable?, tag: UInt32?) {
117-
self.kind = kind
118-
self.identifier = identifier
119-
self.tag = tag
115+
init() {
116+
self.kind = .keyPath(\Void.self)
117+
self.identifier = UUID()
118+
self.tag = nil
120119
}
121120

122121
static func == (lhs: Self, rhs: Self) -> Bool {

Sources/ComposableArchitecture/Reducer/Reducers/DependencyKeyWritingReducer.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ extension Reducer {
7676
// specialization defined below from being called, which fuses chained calls.
7777
-> _DependencyKeyWritingReducer<Self>
7878
{
79-
_DependencyKeyWritingReducer(base: self) { $0[keyPath: keyPath] = value }
79+
_DependencyKeyWritingReducer(base: self) {
80+
$0[keyPath: keyPath] = value
81+
}
8082
}
8183

8284
/// Places a value in the reducer's dependencies.
@@ -144,7 +146,9 @@ extension Reducer {
144146
// specialization defined below from being called, which fuses chained calls.
145147
-> _DependencyKeyWritingReducer<Self>
146148
{
147-
_DependencyKeyWritingReducer(base: self) { transform(&$0[keyPath: keyPath]) }
149+
_DependencyKeyWritingReducer(base: self) {
150+
transform(&$0[keyPath: keyPath])
151+
}
148152
}
149153
}
150154

Sources/ComposableArchitecture/Store.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,11 @@ public final class Store<State, Action> {
174174
@ReducerBuilder<State, Action> reducer: () -> R,
175175
withDependencies prepareDependencies: ((inout DependencyValues) -> Void)? = nil
176176
) {
177-
let prepDeps: (inout DependencyValues) -> Void = {
178-
$0.navigationIDPath = NavigationIDPath(path: [
179-
NavigationID(
180-
kind: .keyPath(\State.self),
181-
identifier: UUID(),
182-
tag: nil
183-
)
184-
])
185-
prepareDependencies?(&$0)
186-
}
187-
let (initialState, reducer, dependencies) = withDependencies(prepDeps) {
177+
let (initialState, reducer, dependencies) = withDependencies(prepareDependencies ?? { _ in }) {
188178
@Dependency(\.self) var dependencies
189-
return (initialState(), reducer(), dependencies)
179+
var updatedDependencies = dependencies
180+
updatedDependencies.navigationIDPath = NavigationIDPath(path: [NavigationID()])
181+
return (initialState(), reducer(), updatedDependencies)
190182
}
191183
self.init(
192184
initialState: initialState,

Sources/ComposableArchitecture/TestStore.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ public final class TestStore<State: Equatable, Action> {
541541
let reducer = Dependencies.withDependencies {
542542
prepareDependencies(&$0)
543543
sharedChangeTracker.track(&$0)
544+
$0.navigationIDPath = NavigationIDPath(path: [NavigationID()])
544545
} operation: {
545546
TestReducer(Reduce(reducer()), initialState: initialState())
546547
}

Tests/ComposableArchitectureTests/StoreTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,30 @@ final class StoreTests: BaseTCATestCase {
12351235
XCTAssertEqual(store1.count, 42)
12361236
XCTAssertEqual(store2.count, 0)
12371237
}
1238+
1239+
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
1240+
@MainActor func testRootStoreCancellationIsolation_TestStore() async throws {
1241+
let clock = TestClock()
1242+
let store1 = TestStore(initialState: RootStoreCancellationIsolation.State()) {
1243+
RootStoreCancellationIsolation()
1244+
} withDependencies: {
1245+
$0.continuousClock = clock
1246+
}
1247+
let store2 = TestStore(initialState: RootStoreCancellationIsolation.State()) {
1248+
RootStoreCancellationIsolation()
1249+
} withDependencies: {
1250+
$0.continuousClock = clock
1251+
}
1252+
await store1.send(.tap)
1253+
await store2.send(.tap)
1254+
try await Task.sleep(nanoseconds: 100_000_000)
1255+
await store2.send(.cancelButtonTapped)
1256+
await clock.run()
1257+
await store1.receive(\.response) {
1258+
$0.count = 42
1259+
}
1260+
}
1261+
12381262
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
12391263
@Reducer struct RootStoreCancellationIsolation {
12401264
@ObservableState struct State: Equatable {

0 commit comments

Comments
 (0)