-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from hotwired/preserve-visit-options-response
Persist visit options if a response is present
- Loading branch information
Showing
3 changed files
with
68 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Foundation | ||
|
||
class VisitOptionsHandler { | ||
|
||
private var unhandledVisitOptions: VisitOptions? | ||
|
||
/// If a form submission provides a response HTML, save the options and pass them to the next visit proposal. | ||
func process(_ options: VisitOptions?) -> VisitOptions { | ||
|
||
if let options, options.response?.responseHTML != nil { | ||
/// A `responseHTML` is provided for the next visit. | ||
unhandledVisitOptions = options | ||
return options | ||
} else if let unhandledVisitOptions { | ||
/// Next visit is happening. Use the previous `responseHTML`. | ||
self.unhandledVisitOptions = nil | ||
return unhandledVisitOptions | ||
} else { | ||
/// No options are unhandled. | ||
return options ?? VisitOptions() | ||
} | ||
} | ||
|
||
} |
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