Skip to content

Instantly share code, notes, and snippets.

@kouphax
Created July 28, 2015 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouphax/6c5598f42e11ab1a873a to your computer and use it in GitHub Desktop.
Save kouphax/6c5598f42e11ab1a873a to your computer and use it in GitHub Desktop.
module Confirm where
import Html exposing (..)
import Html.Events exposing (..)
import Signal exposing (..)
type Action = NoOp | Prompt
actions : Signal.Mailbox Action
actions =
Signal.mailbox NoOp
-- PORTS --------------------------------
port getName : Signal String
port confirm : Signal Int
port confirm =
actions.signal
|> filter (\s -> s == Prompt) NoOp
|> map (always 0) -- I don't really care about the value (impurity)
-- VIEWS --------------------------------
view signal =
div []
[ text signal,
button [ onClick actions.address Prompt ]
[ text "Set Name"]]
main : Signal Html
main = Signal.map view getName
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="confirm.js"></script>
</head>
<body>
</body>
<script type="text/javascript">
var app = Elm.fullscreen(Elm.Confirm, { getName: "" });
app.ports.confirm.subscribe(function(){
var value = window.prompt("Name?");
app.ports.getName.send(value);
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment