-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUuidGenerator.elm
67 lines (43 loc) · 1.15 KB
/
UuidGenerator.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module UuidGenerator exposing (..)
import Html exposing (..)
import Html.Events exposing (onClick)
import Uuid exposing (Uuid)
import Random.Pcg as Random
main : Program Never Model Msg
main =
Html.program { init = init, update = update, view = view, subscriptions = \_ -> Sub.none }
-- MODEL
type alias Model =
Maybe Uuid
init : ( Model, Cmd Msg )
init =
( Nothing, Cmd.none )
-- UPDATE
type Msg
= GenerateNewUuid
| SetUuid Uuid
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GenerateNewUuid ->
( model, Random.generate SetUuid Uuid.uuidGenerator )
SetUuid uuid ->
( Just uuid, Cmd.none )
-- VIEW
view : Model -> Html Msg
view model =
let
viewUuid =
case model of
Just uuid ->
p [] [ text <| Uuid.toString uuid ]
Nothing ->
p [] [ text "" ]
in
div []
[ h1 [] [ text "UUID v.4 Generator" ]
, viewUuid
, p []
[ button [ onClick GenerateNewUuid ] [ text "generate new uuid" ]
]
]