Created
August 26, 2017 07:37
-
-
Save ksunair/1c0c59d2f97cda3d253196734a6672b0 to your computer and use it in GitHub Desktop.
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
module Main exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
type alias Model = | |
{ name : String | |
, inputdata : String | |
} | |
initData : Model | |
initData = | |
{ name = "" | |
, inputdata = "" | |
} | |
type Msg | |
= SayMyName | |
| Clear | |
| Change String | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
SayMyName -> | |
{ model | name = model.inputdata, inputdata = "" } | |
Change val -> | |
{ model | inputdata = val } | |
Clear -> | |
initData | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ h3 [] | |
[ text ("Your name is: " ++ model.name) ] | |
, input | |
[ onInput Change | |
, value model.inputdata | |
] | |
[] | |
, button | |
[ onClick SayMyName ] | |
[ text "Say My Name" ] | |
] | |
main = | |
beginnerProgram { model = initData, view = view, update = update } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment