1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

ui: impl Timer.schedule function

This commit is contained in:
James Hillyerd
2020-04-05 17:27:22 -07:00
parent e8e506f870
commit 4fc8d229eb
2 changed files with 13 additions and 6 deletions

View File

@@ -93,7 +93,7 @@ type Msg
| OpenMailbox | OpenMailbox
| RecentMenuMouseOver | RecentMenuMouseOver
| RecentMenuMouseOut | RecentMenuMouseOut
| RecentMenuTimeout Timer () | RecentMenuTimeout Timer
| RecentMenuToggled | RecentMenuToggled
@@ -155,10 +155,10 @@ update msg model session =
| recentMenuTimer = newTimer | recentMenuTimer = newTimer
} }
, session , session
, Process.sleep 400 |> Task.perform (RecentMenuTimeout newTimer >> model.mapMsg) , Timer.schedule (RecentMenuTimeout >> model.mapMsg) newTimer 400
) )
RecentMenuTimeout timer _ -> RecentMenuTimeout timer ->
if timer == model.recentMenuTimer then if timer == model.recentMenuTimer then
( { model ( { model
| recentMenuVisible = False | recentMenuVisible = False

View File

@@ -1,9 +1,11 @@
module Timer exposing (Timer, cancel, empty, replace) module Timer exposing (Timer, cancel, empty, replace, schedule)
import Process
import Task
{-| Implements an identity to track an asynchronous timer. {-| Implements an identity to track an asynchronous timer.
-} -}
type Timer type Timer
= Empty = Empty
| Idle Int | Idle Int
@@ -15,6 +17,11 @@ empty =
Empty Empty
schedule : (Timer -> msg) -> Timer -> Float -> Cmd msg
schedule message timer millis =
Task.perform (always (message timer)) (Process.sleep millis)
{-| Replaces the provided timer with a newly created one. {-| Replaces the provided timer with a newly created one.
-} -}
replace : Timer -> Timer replace : Timer -> Timer