Skip to content

Instantly share code, notes, and snippets.

@mindbat
Created October 16, 2016 12:07
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 mindbat/edfc8329bd2a97f4f9a00d245fe35ce5 to your computer and use it in GitHub Desktop.
Save mindbat/edfc8329bd2a97f4f9a00d245fe35ce5 to your computer and use it in GitHub Desktop.
Elm Day 2: Echoing Text
import Html exposing (Html, text, input, div)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import String
main = App.program { init = init,
view = view, update = update, subscriptions = \_ -> Sub.none }
-- Model
type alias Model = { content : String }
initialModel : Model
initialModel = { content = "" }
init = (initialModel, Cmd.none)
-- Update
type Msg = Change String
update: Msg -> Model -> ( Model, Cmd Msg)
update msg model = case msg of
Change c -> ({model | content = c}, Cmd.none)
-- View
shout text = String.toUpper text
whisper text = String.toLower text
echo text = (shout text) ++ " " ++ (whisper text)
myStyle = style [ ("width", "100%") ]
view : Model -> Html Msg
view model = div [] [ input [placeholder "Say something", onInput Change, myStyle ]
[], div [ myStyle ] [text (echo (toString model.content))] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment