Elm Day 2: Echoing Text
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
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