0

In update I would like to call my Tick Action every time Input is called.

The scenario is that a user enters a value in a text field, on update the model is updated via Input and then Tick is called and more stuff is performed on the model.

In 0.16 I could do something like this :

Input query ->
  ({ model | query = query }, Effects.tick Tick)

Tick clockTime ->
  -- do something with clockTime

I'm not sure how to do this in 0.17.

I'm not sure if this would be a subscription and if it were, how you could go about configuring it to call Input then Action.

Any help is appreciated.

Denim Demon
  • 734
  • 1
  • 10
  • 23
  • Possible duplicate of [Effects.tick replacement for elm 0.17](http://stackoverflow.com/questions/37196357/effects-tick-replacement-for-elm-0-17) – Chad Gilbert Jun 18 '16 at 10:50

1 Answers1

2

The functionality for retrieving the current time as an effect has been moved into a Task, in the Time module under Time.now.

http://package.elm-lang.org/packages/elm-lang/core/4.0.1/Time#now

You can reproduce your functionality by making the following changes:

1) Make sure there is a NoOp message available in your messages. Time.now returns a Task which we know will never fail, but we still need a failure message to hand to Task.perform

type Msg
  = Input String
  | Tick Time
  | NoOp

2) Replace Effects.tick Tick with Time.now and Task.perform

Input query ->
  ( { model | query = query }
  , Time.now |> Task.perform (\_ -> NoOp) Tick
  )

If you don't like the NoOp message, there are other ways around it, such as using Debug.crash or performFailproof from Task.Extra (found here: http://package.elm-lang.org/packages/NoRedInk/elm-task-extra/2.0.0/Task-Extra#performFailproof)

lukewestby
  • 1,207
  • 8
  • 15