Last active
February 2, 2016 08:37
-
-
Save prozacchiwawa/456ea2986f316dee400b to your computer and use it in GitHub Desktop.
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
module PortTest where | |
{-- | |
<html> | |
<head> | |
<script src='port-test.js'></script> | |
</head> | |
<body> | |
<div id='port-test'></div> | |
<script> | |
var portTest = Elm.embed(Elm.PortTest, document.getElementById('port-test')); | |
portTest.ports.outputPort.subscribe(function (t) { | |
console.log("js-output",t); | |
}); | |
</script> | |
</body> | |
</html> | |
--} | |
import Debug exposing (log) | |
import StartApp | |
import Effects exposing (Effects(..), Never) | |
import Html exposing (div, text) | |
import Html.Events exposing (onClick) | |
import Signal | |
import Task exposing (Task (..)) | |
outputSignal : Signal.Mailbox String | |
outputSignal = | |
Signal.mailbox "" | |
port outputPort : Signal String | |
port outputPort = | |
Signal.map (log "output") outputSignal.signal | |
type Action = Act Int | |
type Model = Model Int | |
update : Action -> Model -> Model | |
update action model = | |
Model ((case model of Model x -> x) + (case (log "action" action) of Act x -> x)) | |
view : Signal.Address Action -> Model -> Html.Html | |
view address model = | |
div [onClick address (Act 1)] [text (toString model)] | |
getActVal a = | |
case a of | |
Act x -> x | |
main : Signal Html.Html | |
main = | |
let app = StartApp.start { | |
init = (Model 0, Effects.none) | |
, update = \a -> \m -> ( | |
update a m, | |
if getActVal a == 0 then Effects.none else Signal.send outputSignal.address (toString m) |> Task.map (\_ -> Act 0) |> Effects.task | |
) | |
, view = view | |
, inputs = [] | |
} in | |
app.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment