Skip to content

Commit f9e0e3d

Browse files
authored
Avoid erasing to AnyView in Routed (#2)
* Add debug navigator * Avoid erasing to AnyView in Routed * Update documentation
1 parent 37efb89 commit f9e0e3d

16 files changed

+1421
-131
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"repositoryURL": "https://github.com/pointfreeco/swift-composable-architecture",
2525
"state": {
2626
"branch": null,
27-
"revision": "b67569f69813140cd9c984db33ee959d9711a008",
28-
"version": "0.9.0"
27+
"revision": "37c6312ba43ec697063abe5956908db6b71aa68a",
28+
"version": "0.11.0"
2929
}
3030
}
3131
]

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let package = Package(
2525
.package(
2626
name: "swift-composable-architecture",
2727
url: "https://github.com/pointfreeco/swift-composable-architecture",
28-
.upToNextMinor(from: "0.11.0")
28+
from: "0.7.0"
2929
),
3030
],
3131
targets: [

Sources/ComposableNavigator/Navigator/Navigator.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import Foundation
22

33
public struct Navigator {
4+
private let _path: () -> [IdentifiedScreen]
45
private let _go: (AnyScreen, ScreenID) -> Void
56
private let _goBack: (AnyScreen) -> Void
67
private let _replace: ([AnyScreen]) -> Void
78
private let _dismiss: (ScreenID) -> Void
89
private let _dismissSuccessor: (ScreenID) -> Void
910
private let _didAppear: (ScreenID) -> Void
1011

12+
func path() -> [IdentifiedScreen] {
13+
_path()
14+
}
15+
1116
public func go<S: Screen>(to screen: S, on id: ScreenID) {
1217
_go(screen.eraseToAnyScreen(), id)
1318
}
@@ -37,13 +42,15 @@ public struct Navigator {
3742
}
3843

3944
public init(
45+
path: @escaping () -> [IdentifiedScreen],
4046
go: @escaping (AnyScreen, ScreenID) -> Void,
4147
goBack: @escaping (AnyScreen) -> Void,
4248
replace: @escaping ([AnyScreen]) -> Void,
4349
dismiss: @escaping (ScreenID) -> Void,
4450
dismissSuccessor: @escaping (ScreenID) -> Void,
4551
didAppear: @escaping (ScreenID) -> Void
4652
) {
53+
self._path = path
4754
self._go = go
4855
self._goBack = goBack
4956
self._replace = replace
@@ -53,8 +60,10 @@ public struct Navigator {
5360
}
5461
}
5562

63+
// MARK: - Stub
5664
public extension Navigator {
5765
static func stub(
66+
path: @escaping () -> [IdentifiedScreen] = { fatalError("path() unimplemented in stub. Make sure to wrap your application in a Root view or inject Navigator via .environment(\\.navigator, navigator) for testing purposes.") },
5867
go: @escaping (AnyScreen, ScreenID) -> Void = { _, _ in fatalError("go(to:) unimplemented in stub. Make sure to wrap your application in a Root view or inject Navigator via .environment(\\.navigator, navigator) for testing purposes.") },
5968
goBack: @escaping (AnyScreen) -> Void = { _ in fatalError("goBack(to:) unimplemented in stub. Make sure to wrap your application in a Root view or inject Navigator via .environment(\\.navigator, navigator) for testing purposes.") },
6069
replace: @escaping ([AnyScreen]) -> Void = { _ in fatalError("replace(path:) unimplemented in stub. Make sure to wrap your application in a Root view or inject Navigator via .environment(\\.navigator, navigator) for testing purposes.") },
@@ -63,6 +72,7 @@ public extension Navigator {
6372
didAppear: @escaping (ScreenID) -> Void = { _ in fatalError("didAppear(id:) unimplemented in stub. Make sure to wrap your application in a Root view or inject Navigator via .environment(\\.navigator, navigator) for testing purposes.") }
6473
) -> Navigator {
6574
Navigator(
75+
path: path,
6676
go: go,
6777
goBack: goBack,
6878
replace: replace,
@@ -72,3 +82,42 @@ public extension Navigator {
7282
)
7383
}
7484
}
85+
86+
// MARK: - Debug
87+
public extension Navigator {
88+
func debug() -> Navigator {
89+
Navigator(
90+
path: path,
91+
go: { (screen, id) in
92+
_go(screen, id)
93+
print("Sent go(to: \(screen), on: \(id)).\nNew path:")
94+
dump(path())
95+
},
96+
goBack: { (predecessor) in
97+
_goBack(predecessor)
98+
print("Sent goBack(to: \(predecessor)).\nNew path:")
99+
dump(path())
100+
},
101+
replace: { (newPath) in
102+
_replace(newPath)
103+
print("Sent replace(path: \(newPath)).\nNew path:")
104+
dump(path())
105+
},
106+
dismiss: { (id) in
107+
_dismiss(id)
108+
print("Sent dismiss(id: \(id)).\nNew path:")
109+
dump(path())
110+
},
111+
dismissSuccessor: { (id) in
112+
_dismissSuccessor(id)
113+
print("Sent dismissSuccessor(of: \(id)).\nNew path:")
114+
dump(path())
115+
},
116+
didAppear: { (id) in
117+
_didAppear(id)
118+
print("Sent didAppear(id: \(id)).\nNew path:")
119+
dump(path())
120+
}
121+
)
122+
}
123+
}

Sources/ComposableNavigator/Navigator/NavigatorDataSource+Navigator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
public extension Navigator {
22
init(dataSource: Navigator.Datasource) {
33
self.init(
4+
path: { dataSource.path },
45
go: { screen, id in
56
dataSource.go(to: screen, on: id)
67
},
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
public struct PathBuilder {
2-
private let _buildPath: ([IdentifiedScreen]) -> Routed?
1+
import SwiftUI
32

4-
public init(buildPath: @escaping ([IdentifiedScreen]) -> Routed?) {
3+
public struct PathBuilder<Content: View> {
4+
private let _buildPath: ([IdentifiedScreen]) -> Content?
5+
6+
public init(buildPath: @escaping ([IdentifiedScreen]) -> Content?) {
57
self._buildPath = buildPath
68
}
79

8-
public func build(path: [IdentifiedScreen]) -> Routed? {
10+
public func build(path: [IdentifiedScreen]) -> Content? {
911
return _buildPath(path)
1012
}
1113
}

0 commit comments

Comments
 (0)