Created
November 13, 2016 13:39
-
-
Save eeue56/91d8bb19b03293b436a44273a1b2a58c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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