Skip to content

Instantly share code, notes, and snippets.

@eeue56
Created November 13, 2016 13:39
Show Gist options
  • Select an option

  • Save eeue56/91d8bb19b03293b436a44273a1b2a58c to your computer and use it in GitHub Desktop.

Select an option

Save eeue56/91d8bb19b03293b436a44273a1b2a58c to your computer and use it in GitHub Desktop.
port module Main exposing (..)
import Random
import Html exposing (Html)
import Html.Events exposing (onClick)
import Html.App
type alias Model = { faceValue : Int }
type Msg = RollDice | SetDiceValue Int
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
RollDice ->
( model, requestNewDiceValue )
SetDiceValue newFaceValue ->
( { model | faceValue = newFaceValue }, Cmd.none )
view : Model -> Html Msg
view model =
Html.div
[]
[ Html.text (toString model.faceValue)
, Html.button [ onClick RollDice ] [ Html.text "roll dice!" ]
]
main =
Html.App.program
{ init = ( { faceValue = 1 }, Cmd.none )
, update = update
, view = view
, subscriptions = newDiceValue SetDiceValue
}
port requestNewDiceValue : Cmd Msg
port newDiceValue : (Int -> Msg) -> Sub Msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment