summaryrefslogtreecommitdiff
blob: 9e162fece83cb384ea3a4742743a190b49cc906a (plain)
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 ElmModule.Update exposing (update)

-- Elm -------------------------------------------------------------------------

-- Main Menu -------------------------------------------------------------------
import Struct.Event
import Struct.Model

import Update.AddPlayer
import Update.HandleServerReply
import Update.RefreshBattles
import Update.StoreParams

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
update : (
      Struct.Event.Type ->
      Struct.Model.Type ->
      (Struct.Model.Type, (Cmd Struct.Event.Type))
   )
update event model =
   let
      new_model = (Struct.Model.clear_error model)
   in
   case event of
      Struct.Event.None -> (model, Cmd.none)

      (Struct.Event.SetUsername str) -> (model, Cmd.none)
      (Struct.Event.SetID str) -> (model, Cmd.none)
      (Struct.Event.SetURLPrefix str) -> (model, Cmd.none)
      (Struct.Event.SetFrequency val) -> (model, Cmd.none)

      Struct.Event.ShouldRefresh -> (Update.RefreshBattles.apply_to model)

      Struct.Event.StoreParams -> (Update.StoreParams.apply_to model)

      Struct.Event.AddPlayer -> (Update.AddPlayer.apply_to model)

      (Struct.Event.Failed err) ->
         (
            (Struct.Model.invalidate err new_model),
            Cmd.none
         )

      (Struct.Event.ServerReplied result) ->
         (Update.HandleServerReply.apply_to model result)