aboutsummaryrefslogtreecommitdiff
path: root/src/Update/Update.elm
blob: 0252fc8301c43297a9e4b4a8fd261fd20aec241d (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
module Update.Update
  ( Action(..)
  , updates
  , update
  ) where

import Signal
import Dict
import Time (Time)
import Maybe

import Model.Model (..)
import Model.Timer (..)
import Model.Id (..)
import Model.IdGenerator (..)

import Update.UpdateTimer (..)

type Action =
  NoOp
  | RenameNewTimer String
  | AddNewTimer
  | DeltaTime Time
  | UpdateTimer Id TimerAction

updates : Signal.Channel Action
updates = Signal.channel NoOp

update : Action -> Model -> Model
update action model =
  case action of
    NoOp -> model
    RenameNewTimer name ->
      { model | newTimerName <- name }
    AddNewTimer ->
      let (id, newTimerIdGenerator) = getId model.timerIdGenerator
      in  { model
          | timers <- Dict.insert id (initialTimer model.currentTime model.newTimerName) model.timers
          , timerIdGenerator <- newTimerIdGenerator
          , newTimerName <- ""
          }
    DeltaTime delta ->
      { model
      | currentTime <- model.currentTime + delta
      , timers <- substractTimersTime delta model.timers
      }
    UpdateTimer id action ->
      { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers }