Skip to content

Instantly share code, notes, and snippets.

@joanllenas
Created January 2, 2018 21:47
Show Gist options
  • Save joanllenas/80974f07b3f65ee5e8f687527b76d5d6 to your computer and use it in GitHub Desktop.
Save joanllenas/80974f07b3f65ee5e8f687527b76d5d6 to your computer and use it in GitHub Desktop.
Ejemplo 2 del post "Un sorbo de TEA"
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
}
-- UPDATE
type Msg
= Incrementar
| Decrementar
actualizar mensaje miModelo =
case mensaje of
Incrementar ->
{ miModelo | cont = miModelo.cont + 1 }
Decrementar ->
{ miModelo | cont = miModelo.cont - 1 }
-- VIEW
vista miModelo =
div []
[ span [ style [ ( "padding", "5px" ) ] ] [ text (toString miModelo.cont) ]
, button [ onClick Incrementar ] [ text "+1" ]
, button [ onClick Decrementar ] [ text "-1" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment