Skip to content

Instantly share code, notes, and snippets.

@jmn
Created October 2, 2017 07:26
Show Gist options
  • Save jmn/09811cee199be963b7dcd426dc429419 to your computer and use it in GitHub Desktop.
Save jmn/09811cee199be963b7dcd426dc429419 to your computer and use it in GitHub Desktop.
Elm 0.18 Add to list
module Main exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type alias Model =
{ tweets : List String
, new_tweet : String
}
model : Model
model =
Model [] ""
type Msg
= Tweet
| ChangeTweet String
update : Msg -> Model -> (Model)
update msg model =
case msg of
Tweet ->
{ model | tweets = model.tweets ++ [model.new_tweet] }
ChangeTweet x ->
{ model | new_tweet = x}
main : Program Never Model Msg
main =
Html.beginnerProgram {
model = model
, view = view
, update = update
}
view : Model -> Html Msg
view model =
div []
[ div []
[ input [ type_ "text", onInput ChangeTweet] []
, button [ onClick Tweet ] [ text "Tweet" ]
, tweetListing model
]
]
tweetListing : Model -> Html Msg
tweetListing model =
div [ ] [ text "tweets shown here"
, ul [] (List.map singleTweet model.tweets)]
singleTweet : String -> Html Msg
singleTweet t =
li [] [text t]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment