mirror of
https://github.com/correl/elm-exercise.git
synced 2024-11-27 11:09:53 +00:00
33 lines
508 B
Elm
33 lines
508 B
Elm
module Demo.User (..) where
|
|
|
|
import Html exposing (Html)
|
|
import Html.Attributes exposing (class)
|
|
import Json.Decode exposing (Decoder, (:=))
|
|
|
|
|
|
type alias Model =
|
|
{ id : Int
|
|
, name : String
|
|
}
|
|
|
|
|
|
view : Model -> Html
|
|
view user =
|
|
Html.li
|
|
[]
|
|
[ Html.text user.name ]
|
|
|
|
|
|
list : List Model -> Html
|
|
list users =
|
|
Html.ul
|
|
[ class "users" ]
|
|
<| List.map view users
|
|
|
|
|
|
decode : Decoder Model
|
|
decode =
|
|
Json.Decode.object2
|
|
Model
|
|
("id" := Json.Decode.int)
|
|
("name" := Json.Decode.string)
|