Skip to content

Commit

Permalink
Add bundle parameter to route
Browse files Browse the repository at this point in the history
Backfills turbo-ios PR #207:
hotwired/turbo-ios#207
  • Loading branch information
joemasilotti committed May 15, 2024
1 parent 7384411 commit 958fcd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Source/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import Foundation
///
/// - Note: See `NumbersViewController` in the demo app for an example.
public protocol Router: AnyObject {
func route(_: URL)
func route(_ url: URL)

func route(_ proposal: VisitProposal)
}

extension Navigator: Router {}
extension Navigator: Router {
public func route(_ url: URL) {
route(url, parameters: nil)
}
}
5 changes: 3 additions & 2 deletions Source/Turbo/Navigator/Navigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public class Navigator {
/// Convenience function to routing a proposal directly.
///
/// - Parameter url: the URL to visit
public func route(_ url: URL) {
/// - Parameter parameters: provide context relevant to `url`
public func route(_ url: URL, parameters: [String: Any]? = nil) {
let options = VisitOptions(action: .advance, response: nil)
let properties = session.pathConfiguration?.properties(for: url) ?? PathProperties()
route(VisitProposal(url: url, options: options, properties: properties))
route(VisitProposal(url: url, options: options, properties: properties, parameters: parameters))
}

/// Transforms `VisitProposal` -> `UIViewController`
Expand Down
4 changes: 3 additions & 1 deletion Source/Turbo/Visit/VisitProposal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public struct VisitProposal {
public let url: URL
public let options: VisitOptions
public let properties: PathProperties
public let parameters: [String: Any]?

public init(url: URL, options: VisitOptions, properties: PathProperties = [:]) {
public init(url: URL, options: VisitOptions, properties: PathProperties = [:], parameters: [String: Any]? = nil) {
self.url = url
self.options = options
self.properties = properties
self.parameters = parameters
}
}

0 comments on commit 958fcd8

Please sign in to comment.