Last active
August 22, 2016 16:02
-
-
Save roine/cef3bcab34a03f98fd9c735718c93f03 to your computer and use it in GitHub Desktop.
confirm in ELM using Native
This file contains hidden or 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
module Confirm exposing (confirm) | |
import Native.Confirm | |
import Task exposing (Task) | |
confirm : String -> Task () () | |
confirm str = | |
Native.Confirm.doConfirm str |
This file contains hidden or 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
// In Native/Confirm | |
var _roine$my_plugin$Native_Confirm = function() { | |
function doConfirm(str) { | |
return _elm_lang$core$Native_Scheduler.nativeBinding(function(callback) { | |
if (window.confirm(str)) { | |
callback(_elm_lang$core$Native_Scheduler.succeed()); | |
} | |
}); | |
} | |
return { | |
doConfirm: doConfirm | |
}; | |
}(); |
This file contains hidden or 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
... | |
update msg model = | |
case msg of | |
CloseReport -> | |
model ! [ Task.perform (always NoOp) (always DoCloseReport) (confirm "are you sure?") ] | |
DoCloseReport -> | |
model ! [ closeReport ] | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment