-
Notifications
You must be signed in to change notification settings - Fork 36
/
Update.elm
51 lines (42 loc) · 1.05 KB
/
Update.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
module Config.Update where
import Config exposing (backends)
import Config.Model exposing (initialModel, Model)
import Effects exposing (Effects)
import Task exposing (map)
import WebAPI.Location exposing (location)
init : (Model, Effects Action)
init =
( initialModel
, getConfigFromUrl
)
type Action
= SetConfig Config.Model.BackendConfig
| SetError
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
SetConfig backendConfig ->
( { model | backendConfig = backendConfig }
, Effects.none
)
SetError ->
( { model | error = True }
, Effects.none
)
-- EFFECTS
getConfigFromUrl : Effects Action
getConfigFromUrl =
let
getAction location =
let
config =
List.filter (\backend -> backend.hostname == location.hostname) backends
|> List.head
in
case config of
Just val -> SetConfig val
Nothing -> SetError
actionTask =
Task.map getAction WebAPI.Location.location
in
Effects.task actionTask