-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.elm
81 lines (53 loc) · 1.37 KB
/
App.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
port module App exposing (..)
import Html exposing (Html, text, ul, li, program)
import Html.Events exposing (onClick)
import Html.Attributes exposing (id, attribute)
import Towns
import Places
-- Main
main : Program Never Model Msg
main =
program
{ init = init
, view = view
, update = update
, subscriptions = (\_ -> Sub.none)
}
-- Init
type alias Model =
Towns.Town
init : ( Model, Cmd Msg )
init =
( Towns.defaultTown
, Cmd.batch
[ portActiveTown Towns.defaultTown
, portPlaces Places.places
]
)
-- UPDATE
port portActiveTown : Towns.Town -> Cmd msg
port portPlaces : List Places.Place -> Cmd msg
type Msg
= SelectTown Towns.Town
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SelectTown town ->
( town, portActiveTown town )
-- View
view : Model -> Html Msg
view model =
let
townsLi : List Towns.Town -> List (Html Msg)
townsLi towns =
List.map
(\town ->
li
[ attribute "data-selected" (toString (town.name == model.name))
, onClick (SelectTown town)
]
[ text town.name ]
)
towns
in
ul [ id "towns" ] (townsLi Towns.towns)