-
Notifications
You must be signed in to change notification settings - Fork 22
/
App.elm
70 lines (48 loc) · 1.33 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
port module App exposing (Model, Msg(..), init, input, options, output, subscriptions, update, view)
import Dict exposing (Dict)
import Html exposing (Html, div, text)
import Html.Attributes exposing (id)
type alias Model =
{ selection : Maybe String }
modelToString : Model -> String
modelToString model =
case model.selection of
Nothing ->
"Nothing"
Just s ->
"Just " ++ s
init : ( Model, Cmd Msg )
init =
( Model Nothing, output (Dict.toList options) )
type Msg
= Select String
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Select val ->
let
option : Maybe String
option =
Dict.get val options
in
( { model | selection = option }, Cmd.none )
view : Model -> Html Msg
view model =
div
[]
[ text (modelToString model)
, div [ id "select2-container" ] []
]
port output : List ( String, String ) -> Cmd msg
port input : (String -> msg) -> Sub msg
options : Dict String String
options =
Dict.fromList
[ ( "US", "United States" )
, ( "UK", "United Kingdom" )
, ( "UY", "Uruguay" )
, ( "UZ", "Uzbekistan" )
]
subscriptions : Model -> Sub Msg
subscriptions model =
input Select