aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
Diffstat (limited to 'src/Update')
-rw-r--r--src/Update/Update.elm48
-rw-r--r--src/Update/UpdateTimer.elm16
2 files changed, 64 insertions, 0 deletions
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
new file mode 100644
index 0000000..0252fc8
--- /dev/null
+++ b/src/Update/Update.elm
@@ -0,0 +1,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 }
diff --git a/src/Update/UpdateTimer.elm b/src/Update/UpdateTimer.elm
new file mode 100644
index 0000000..d8861b7
--- /dev/null
+++ b/src/Update/UpdateTimer.elm
@@ -0,0 +1,16 @@
+module Update.UpdateTimer
+ ( TimerAction(..)
+ , updateTimer
+ ) where
+
+import Model.Timer (..)
+import Model.Id (..)
+
+type TimerAction =
+ ToggleRunning
+
+updateTimer : TimerAction -> Timer -> Timer
+updateTimer action timer =
+ case action of
+ ToggleRunning ->
+ { timer | isRunning <- not timer.isRunning }