Created
September 19, 2018 10:16
-
-
Save spookylukey/d7fe094911a22944ff519eda948a4fcb to your computer and use it in GitHub Desktop.
Elm 0.18 confirm Task
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
// Native/Confirm.js | |
var _user$project$Native_Confirm = function () { | |
var scheduler = _elm_lang$core$Native_Scheduler; | |
function confirmTask(prompt, successValue, failValue) { | |
return scheduler.nativeBinding(function (callback) { | |
if (window.confirm(prompt)) { | |
callback(scheduler.succeed(successValue)); | |
} else { | |
callback(scheduler.fail(failValue)); | |
} | |
}); | |
}; | |
return { | |
confirmTask: F3(confirmTask), | |
} | |
}() | |
// In addition you need this Elm code: | |
// import Native.Confirm | |
// | |
// {-| Provided with a prompt, a success Msg and a failure Msg, use standard | |
// window.confirm to decide which to run and run it. | |
// | |
// -} | |
// confirm : String -> Msg -> Msg -> Cmd Msg | |
// confirm prompt success fail = | |
// confirmTask prompt success fail |> runConfirm | |
// | |
// confirmTask : String -> b -> a -> Task.Task a b | |
// confirmTask = | |
// Native.Confirm.confirmTask | |
// | |
// runConfirm : Task.Task Msg Msg -> Cmd Msg | |
// runConfirm task = | |
// Task.attempt | |
// (\result -> | |
// case result of | |
// Ok success -> | |
// success | |
// | |
// Err fail -> | |
// fail | |
// ) | |
// task | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment