Skip to content

Commit f94f842

Browse files
committed
fix cancellation id prefix.
1 parent da6b134 commit f94f842

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

Sources/ComposableArchitecture/Internal/NavigationID.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ struct NavigationIDPath: Hashable, Sendable {
2323

2424
var prefixes: [NavigationIDPath] {
2525
(0...self.path.count).map { index in
26-
NavigationIDPath(path: Array(self.path.dropFirst(index)))
26+
NavigationIDPath(path: Array(self.path.prefix(self.path.count - index)))
2727
}
2828
}
2929

3030
func appending(_ element: NavigationID) -> Self {
3131
.init(path: self.path + [element])
3232
}
3333

34+
mutating func append(_ element: NavigationID) {
35+
self.path.append(element)
36+
}
37+
3438
public var id: Self { self }
3539
}
3640

Sources/ComposableArchitecture/Store.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public final class Store<State, Action> {
177177
let (initialState, reducer, dependencies) = withDependencies(prepareDependencies ?? { _ in }) {
178178
@Dependency(\.self) var dependencies
179179
var updatedDependencies = dependencies
180-
updatedDependencies.navigationIDPath = NavigationIDPath(path: [NavigationID()])
180+
updatedDependencies.navigationIDPath.append(NavigationID())
181181
return (initialState(), reducer(), updatedDependencies)
182182
}
183183
self.init(

Sources/ComposableArchitecture/TestStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +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()])
544+
$0.navigationIDPath.append(NavigationID())
545545
} operation: {
546546
TestReducer(Reduce(reducer()), initialState: initialState())
547547
}

Tests/ComposableArchitectureTests/Reducers/PresentationReducerTests.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ final class PresentationReducerTests: BaseTCATestCase {
11091109
await presentationTask.cancel()
11101110
}
11111111

1112-
func testNavigation_cancelID_parentCancellation() async {
1112+
func testNavigation_cancelID_parentCancellation() async throws {
11131113
struct Grandchild: Reducer {
11141114
struct State: Equatable {}
11151115
enum Action: Equatable {
@@ -1193,17 +1193,15 @@ final class PresentationReducerTests: BaseTCATestCase {
11931193
let store = await TestStore(initialState: Parent.State()) {
11941194
Parent()
11951195
}
1196-
let childPresentationTask = await store.send(.presentChild) {
1196+
await store.send(.presentChild) {
11971197
$0.child = Child.State()
11981198
}
1199-
let grandchildPresentationTask = await store.send(.child(.presented(.presentGrandchild))) {
1199+
await store.send(.child(.presented(.presentGrandchild))) {
12001200
$0.child?.grandchild = Grandchild.State()
12011201
}
12021202
await store.send(.child(.presented(.startButtonTapped)))
12031203
await store.send(.child(.presented(.grandchild(.presented(.startButtonTapped)))))
12041204
await store.send(.stopButtonTapped)
1205-
await grandchildPresentationTask.cancel()
1206-
await childPresentationTask.cancel()
12071205
}
12081206

12091207
func testNavigation_cancelID_parentCancelTwoChildren() async {

Tests/ComposableArchitectureTests/StoreTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,6 @@ final class StoreTests: BaseTCATestCase {
12511251
}
12521252
await store1.send(.tap)
12531253
await store2.send(.tap)
1254-
try await Task.sleep(nanoseconds: 100_000_000)
12551254
await store2.send(.cancelButtonTapped)
12561255
await clock.run()
12571256
await store1.receive(\.response) {

0 commit comments

Comments
 (0)