-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunWithFlags.elm
57 lines (45 loc) · 1.21 KB
/
FunWithFlags.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
module FunWithFlags exposing (main)
import Html exposing (Html, text, programWithFlags, h1)
import Types exposing (Meter)
import View exposing (meterList, container)
import Json.Decode
import JsonDecoding exposing (metersDecoder)
type alias Model =
{ meters : List Meter
, locale : String
}
type alias Flags =
{ meters : Json.Decode.Value
, locale : String
}
main : Program Flags Model msg
main =
programWithFlags
{ init = init
, update = (\_ model -> model ! [])
, subscriptions = (\_ -> Sub.none)
, view = view
}
init : Flags -> ( Model, Cmd msg )
init flags =
let
model =
{ meters = [], locale = flags.locale }
in
case Json.Decode.decodeValue metersDecoder flags.meters of
Ok meters ->
{ model | meters = meters } ! []
Err err ->
let
_ =
Debug.crash err
in
model ! []
view : Model -> Html msg
view model =
container
(Just ( "/ports.html", "Ports" ))
[ h1 [] [ text ("Fun with flags (in " ++ model.locale ++ ")") ]
, meterList model.meters
]
[]