Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Window.prompt behavior. #587

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions core/source/Window.mint
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,24 @@ module Window {
Shows the default prompt popup of the browser with the given message and
value.

This function returns a promise but blocks execution until the popup is
closed.

input = Window.prompt("How old are you?")
This function returns the entered text as a `Maybe(String)` and blocks
execution until the popup is closed. If the user cancelled the popup it
returns `Maybe::Nothing`.

case (Window.prompt("How old are you?")) {
Maybe::Just(value) => Debug.log(value)
Maybe::Nothing => Debug.log("User cancelled")
}
*/
fun prompt (label : String, current : String) : Promise(String, String) {
fun prompt (label : String, current : String = "") : Promise(Maybe(String)) {
`
new Promise((resolve, reject) => {
new Promise((resolve) => {
let result = window.prompt(#{label}, #{current})

if (result) {
resolve(result)
if (result !== null) {
resolve(#{Maybe::Just(`result`)})
} else {
reject("User cancelled!")
resolve(#{Maybe::Nothing})
}
})
`
Expand Down