Hello all
Sorry i'm new in Elm, could you clarify
I've made exercise in *checkboxes *example, please review it, Am i in right
way?
import Html exposing (..)
import Html.App exposing (beginnerProgram)
import Html.Attributes exposing (..)
import Html.Events exposing (onCheck)
main =
beginnerProgram { model = model, view = view, update = update }
-- MODEL
type alias Model =
{ red : Bool
, underline : Bool
, bold : Bool
}
model : Model
model =
Model False False True
-- UPDATE
type Msg
= Red Bool
| Underline Bool
| Bold Bool
update : Msg -> Model -> Model
update msg model =
case msg of
Red bool ->
{ model | red = bool }
Underline bool ->
{ model | underline = bool }
Bold bool ->
{ model | bold = bool }
-- VIEW
view : Model -> Html Msg
view model =
let
myLabel: Bool -> ( Bool -> Msg ) -> Html Msg
myLabel newChecked event =
label []
[ br [] []
, input [ type' "checkbox", checked newChecked, onCheck event ] []
, text "red"
]
in
div []
[ span [toStyle model] [ text "Hello, how are you?!"]
, myLabel model.red Red
, myLabel model.underline Underline
, myLabel model.bold Bold
]
toStyle : Model -> Attribute msg
toStyle model =
style
[ ("color", if model.red then "red" else "black")
, ("text-decoration", if model.underline then "underline" else "none")
, ("font-weight", if model.bold then "bold" else "normal")
]
-- Exercise: move the repetative code in `view` into a separate function
-- and use it three times.
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.