Skip to content

Commit a1b1599

Browse files
authored
Navigation case study fixes (#130)
* Fix navigation case study cancellation Fixes #129. * Fix * move
1 parent 11be1b6 commit a1b1599

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Examples/CaseStudies/SwiftUICaseStudies/00-RootView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,15 @@ struct RootView: View {
304304
}
305305
}
306306
.navigationBarTitle("Case Studies")
307+
.onAppear { self.id = UUID() }
308+
309+
Text("\(self.id)")
307310
}
308311
.navigationViewStyle(StackNavigationViewStyle())
309312
}
313+
// NB: This is a hack to force the root view to re-compute itself each time it appears so that
314+
// each demo is provided a fresh store each time.
315+
@State var id = UUID()
310316
}
311317

312318
struct RootView_Previews: PreviewProvider {

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-Lists-LoadThenNavigate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ let lazyListNavigationReducer = Reducer<
3434
LazyListNavigationState, LazyListNavigationAction, LazyListNavigationEnvironment
3535
>.combine(
3636
Reducer { state, action, environment in
37+
struct CancelId: Hashable {}
38+
3739
switch action {
3840
case .counter:
3941
return .none
@@ -43,8 +45,6 @@ let lazyListNavigationReducer = Reducer<
4345
state.rows[index].isActivityIndicatorVisible = state.rows[index].id == id
4446
}
4547

46-
struct CancelId: Hashable {}
47-
4848
return Effect(value: .setNavigationSelectionDelayCompleted(id))
4949
.delay(for: 1, scheduler: environment.mainQueue)
5050
.eraseToEffect()
@@ -53,9 +53,9 @@ let lazyListNavigationReducer = Reducer<
5353
case .setNavigation(selection: .none):
5454
if let selection = state.selection {
5555
state.rows[id: selection.id]?.count = selection.count
56-
state.selection = nil
5756
}
58-
return .none
57+
state.selection = nil
58+
return .cancel(id: CancelId())
5959

6060
case let .setNavigationSelectionDelayCompleted(id):
6161
state.rows[id: id]?.isActivityIndicatorVisible = false

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-Lists-NavigateAndLoad.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ let eagerListNavigationReducer = Reducer<
5050
case .setNavigation(selection: .none):
5151
if let selection = state.selection, let count = selection.value?.count {
5252
state.rows[id: selection.id]?.count = count
53-
state.selection = nil
5453
}
54+
state.selection = nil
5555
return .cancel(id: CancelId())
5656

5757
case .setNavigationSelectionDelayCompleted:

Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Dispatch
44
extension Reducer {
55
/// Prints debug messages describing all received actions and state mutations.
66
///
7-
/// Printing is only done in DEBUG builds.
7+
/// Printing is only done in debug (`#if DEBUG`) builds.
88
///
99
/// - Parameters:
1010
/// - prefix: A string with which to prefix all debug messages.
@@ -24,7 +24,7 @@ extension Reducer {
2424

2525
/// Prints debug messages describing all received actions.
2626
///
27-
/// Printing is only done in DEBUG builds.
27+
/// Printing is only done in debug (`#if DEBUG`) builds.
2828
///
2929
/// - Parameters:
3030
/// - prefix: A string with which to prefix all debug messages.

0 commit comments

Comments
 (0)