From 958fcd8bb9e6ca4005822cd39374caf0828d5c6a Mon Sep 17 00:00:00 2001 From: Joe Masilotti Date: Wed, 15 May 2024 09:48:44 -0700 Subject: [PATCH] Add bundle parameter to route Backfills turbo-ios PR #207: https://github.com/hotwired/turbo-ios/pull/207 --- Source/Router.swift | 8 ++++++-- Source/Turbo/Navigator/Navigator.swift | 5 +++-- Source/Turbo/Visit/VisitProposal.swift | 4 +++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Source/Router.swift b/Source/Router.swift index 7dfc809..74174a0 100644 --- a/Source/Router.swift +++ b/Source/Router.swift @@ -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) + } +} diff --git a/Source/Turbo/Navigator/Navigator.swift b/Source/Turbo/Navigator/Navigator.swift index c7be655..ca328f3 100644 --- a/Source/Turbo/Navigator/Navigator.swift +++ b/Source/Turbo/Navigator/Navigator.swift @@ -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` diff --git a/Source/Turbo/Visit/VisitProposal.swift b/Source/Turbo/Visit/VisitProposal.swift index 5822c74..8c6d10e 100644 --- a/Source/Turbo/Visit/VisitProposal.swift +++ b/Source/Turbo/Visit/VisitProposal.swift @@ -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 } }