Skip to content

Instantly share code, notes, and snippets.

@A-gambit
Created July 24, 2015 16:26
Show Gist options
  • Save A-gambit/b60820817834bbef070a to your computer and use it in GitHub Desktop.
Save A-gambit/b60820817834bbef070a to your computer and use it in GitHub Desktop.
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