Created
April 27, 2017 02:20
-
-
Save boiyama/b1549132ddf029cc11e139a0f2e83bb2 to your computer and use it in GitHub Desktop.
Simple form example in Elm
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, beginnerProgram, div, button, input, li, text, ul) | |
import Html.Attributes exposing (value) | |
import Html.Events exposing (onClick, onInput) | |
import List exposing (map) | |
type alias Model = | |
{ value : String | |
, posts : List String | |
} | |
model : Model | |
model = | |
Model "" [] | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ div [] | |
[ input [ value model.value, onInput ChangeValue ] [] | |
, button [ onClick Send ] [ text "Send" ] | |
] | |
, ul [] (map (\post -> li [] [ text post ]) model.posts) | |
] | |
type Msg | |
= ChangeValue String | |
| Send | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
ChangeValue value -> | |
{ model | value = value } | |
Send -> | |
Model "" (model.posts ++ [ model.value ]) | |
main : Program Never Model Msg | |
main = | |
beginnerProgram | |
{ model = model | |
, view = view | |
, update = update | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment