I had asked this question already:
How do I get the current time in Elm?
And answered it by writing my own (now deprecated) variant of start-ap
I have an answer to my own question (based on a suggestion by amilner42). I'm using this solution in my current code.
I very much like the solution by @w.brian, but functions in messages break the debugger.
I like the solution by @robertjlooby, and this is is very similar, though it does away with an extra type, and is updated for 0.18.
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
model ! []
TickThen msg ->
model ! [ Task.perform (Tock msg) Time.now ]
Tock msg time ->
updateTimeStampedModel msg { model | time = time }
otherMsg ->
update (TickThen msg) model
updateTimeStampedModel : Msg -> Model -> ( Model, Cmd Msg )
updateTimeStampedModel msg model =
case msg of
NoOp ->
update msg model
TickThen _ ->
update msg model
Tock _ _ ->
update msg model
-- ALL OTHER MESSAGES ARE HANDLED HERE, AND ARE CODED TO ASSUME model.time IS UP-TO-DATE.