-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix router lemmy link resolution (#644)
- Loading branch information
Showing
8 changed files
with
270 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Routable.swift | ||
// Mlem | ||
// | ||
// Created by Bosco Ho on 2023-09-22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Conforming types can be added to a `NavigationRouter`'s path. | ||
protocol Routable: Hashable { | ||
|
||
/// - Parameter value: A data type for a given navigation destination. This value could be (but not limited to) some raw data, a view model, or an enum case (representing a route on a navigation path). | ||
/// - Returns: `nil` if data value cannot be mapped to a navigation route. | ||
static func makeRoute<V>(_ value: V) throws -> Self where V: Hashable | ||
|
||
/// Generic error string | ||
static var makeRouteErrorString: String { get } | ||
} | ||
|
||
enum RoutableError<V: Hashable>: LocalizedError { | ||
case routeNotConfigured(value: V) | ||
} | ||
|
||
extension Routable { | ||
|
||
/// Default implementation. | ||
static func makeRoute<V>(_ value: V) throws -> Self where V: Hashable { | ||
switch value { | ||
case let value as Self: | ||
return value | ||
default: | ||
throw RoutableError.routeNotConfigured(value: value) | ||
} | ||
} | ||
|
||
static var makeRouteErrorString: String { | ||
"`makeRoute(...) implementation must return a valid route for all valid data values." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.