Skip to content

Instantly share code, notes, and snippets.

@galderz
Last active March 30, 2016 12:59
Show Gist options
  • Save galderz/6565429509b579d3dcc0c6507871ded8 to your computer and use it in GitHub Desktop.
Save galderz/6565429509b579d3dcc0c6507871ded8 to your computer and use it in GitHub Desktop.
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="app"></div>
<script src="main.js"></script>
<script>
var node = document.getElementById('app');
var app = Elm.embed(Elm.Main, node);
</script>
</body>
<script type="text/javascript" src="infinispan-ports.js"></script>
</html>
function logger(data) {
console.log('Data: ' + data);
}
app.ports.putKeyValue.subscribe(logger);
import StartApp
import PutKeyValue exposing (init, update, view)
app =
StartApp.start
{ init = init
, update = update
, view = view
, inputs = []
}
main =
app.html
port putKeyValue : Signal PutKeyValue.Model
port putKeyValue = app.model
module PutKeyValue where
import Effects exposing (Effects, Never)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (on, targetValue, onClick)
import Signal exposing (Address)
import StartApp.Simple as StartApp
import String
-- MODEL
type alias Model =
{ key : String
, value : String
}
init : (Model, Effects Action)
init =
(Model "" "", Effects.none)
-- UPDATE
type Action
= Key String
| Value String
| Put
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Key key ->
({ model | key = key }, Effects.none)
Value value ->
({ model | value = value }, Effects.none)
Put ->
(model, Effects.none)
-- VIEW
view : Address Action -> Model -> Html
view address model =
div []
[ field "key" address Key "Key" model.key
, field "value" address Value "Value" model.value
, button [ onClick address Put ] [ text "Put" ]
]
field : String -> Address Action -> (String -> Action) -> String -> String -> Html
field fieldType address toAction name content =
div []
[ div [fieldNameStyle "160px"] [text name]
, input
[ type' fieldType
, placeholder name
, value content
, on "input" targetValue (\string -> Signal.message address (toAction string))
]
[]
]
fieldNameStyle : String -> Attribute
fieldNameStyle px =
style
[ ("width", px)
, ("padding", "10px")
, ("text-align", "right")
, ("display", "inline-block")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment