-
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.
Persist visit options if a response is present
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
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 != nil { | ||
/// Options are provided for the next visit. | ||
unhandledVisitOptions = options | ||
return options | ||
} else if let unhandledVisitOptions { | ||
/// Next visit is happening. Use the previous visit options. | ||
self.unhandledVisitOptions = nil | ||
return unhandledVisitOptions | ||
} else { | ||
/// No options are unhandled. | ||
return options ?? VisitOptions() | ||
} | ||
} | ||
|
||
} |