Created
July 24, 2015 16:26
-
-
Save A-gambit/b60820817834bbef070a to your computer and use it in GitHub Desktop.
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
import Html exposing (Html, Attribute, text, toElement, div, input, button) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (on, targetValue, onClick) | |
import Signal exposing (Address) | |
import StartApp | |
import String | |
main = | |
StartApp.start { model = model, view = view, update = update } | |
type alias Model = | |
{ val : String | |
, list : List String | |
} | |
model : Model | |
model = { | |
val = "" | |
, list = [] | |
} | |
view : Address Action -> Model -> Html | |
view address model = | |
div [] | |
[ input | |
[ placeholder "Text to reverse" | |
, value model.val | |
, on "input" targetValue (\string -> Signal.message address (UpdVal string)) | |
] | |
[] | |
, button [onClick address Add] [text "press me"] | |
, div [] [ text (List.concat model.val) ] | |
] | |
type Action = Add | UpdVal String | |
update : Action -> Model -> Model | |
update action model = | |
case action of | |
Add -> {model | list <- model.list ++ [model.val]} | |
UpdVal newVal -> {model | val <- newVal } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment