Last active
January 4, 2018 11:39
-
-
Save joanllenas/a15071090feec2c2ee7d7e4d7d6f636e to your computer and use it in GitHub Desktop.
Ejemplo del post "Otro sorbo de TEA"
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 Counter exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
programParams = | |
{ model = modelo | |
, view = vista | |
, update = actualizar | |
} | |
main = | |
Html.beginnerProgram programParams | |
-- MODEL | |
modelo = | |
{ cont = 0 | |
, incremento = 1 | |
} | |
-- UPDATE | |
type Msg | |
= Incrementar | |
| Decrementar | |
| CambiarIncremento String | |
actualizar mensaje miModelo = | |
case mensaje of | |
Incrementar -> | |
{ miModelo | cont = miModelo.cont + miModelo.incremento } | |
Decrementar -> | |
{ miModelo | cont = miModelo.cont - miModelo.incremento } | |
CambiarIncremento incr -> | |
{ miModelo | incremento = Result.withDefault 0 (String.toInt incr) } | |
-- VIEW | |
vista miModelo = | |
div [] | |
[ span [ style [ ( "padding", "5px" ) ] ] [ text (toString miModelo.cont) ] | |
, button [ onClick Incrementar ] [ text "+" ] | |
, button [ onClick Decrementar ] [ text "-" ] | |
, input [ type_ "number", value (toString miModelo.incremento), onInput CambiarIncremento ] [] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment