forked from evancz/elm-architecture-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e438f46
commit cbdae1f
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Html exposing (..) | ||
import Html.App as Html | ||
import Html.Events exposing (..) | ||
import Random | ||
|
||
|
||
|
||
main = | ||
Html.program | ||
{ init = init | ||
, view = view | ||
, update = update | ||
, subscriptions = subscriptions | ||
} | ||
|
||
|
||
|
||
-- MODEL | ||
|
||
|
||
type alias Model = | ||
{ dieFace : Int | ||
} | ||
|
||
|
||
init : (Model, Cmd Msg) | ||
init = | ||
(Model 1, Cmd.none) | ||
|
||
|
||
|
||
-- UPDATE | ||
|
||
|
||
type Msg | ||
= Roll | ||
| NewFace Int | ||
|
||
|
||
update : Msg -> Model -> (Model, Cmd Msg) | ||
update msg model = | ||
case msg of | ||
Roll -> | ||
(model, Random.generate NewFace (Random.int 1 6)) | ||
|
||
NewFace newFace -> | ||
(Model newFace, Cmd.none) | ||
|
||
|
||
|
||
-- SUBSCRIPTIONS | ||
|
||
|
||
subscriptions : Model -> Sub Msg | ||
subscriptions model = | ||
Sub.none | ||
|
||
|
||
|
||
-- VIEW | ||
|
||
|
||
view : Model -> Html Msg | ||
view model = | ||
div [] | ||
[ h1 [] [ text (toString model.dieFace) ] | ||
, button [ onClick Roll ] [ text "Roll" ] | ||
] |