how to stop subscription?

809 views
Skip to first unread message

诺铁

unread,
May 26, 2016, 10:53:08 PM5/26/16
to elm-d...@googlegroups.com
hi,

there is an exercise:

Exercises:

  • Add a button to pause the clock, turning the Time subscription off.
but I search the api doc, and didn't find out how to do this? any hints?

Max Goldstein

unread,
May 27, 2016, 12:49:47 AM5/27/16
to Elm Discuss
What's the type of the thing passed to Html.App.program that controls subscriptions?

Gage Peterson

unread,
May 27, 2016, 2:11:18 AM5/27/16
to Elm Discuss
I'm not sure it's possible at this point. One way would be to simply ignore them based on some state in the model. Like a boolean called "trackTime" that would only react to the time if it was true. 

诺铁

unread,
May 27, 2016, 2:36:09 AM5/27/16
to elm-d...@googlegroups.com
I add a "shouldStop: Bool" flag to the model. and check it in subscription definition:

subscriptions : Model -> Sub Msg
subscriptions model =
  if model.shouldStop then
    Sub.none
  else
    Time.every second Tick

It works!  but this confuse me. 
doesn't this mean,whenever model is changed, the subscription is reevaluated?

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Wilson

unread,
May 27, 2016, 4:37:44 AM5/27/16
to Elm Discuss
Correct: Every time the global update function in your app runs for any reason, the global subscriptions object is reevaluated as well, and effect managers receive the new list of current subscriptions.

Gage Peterson

unread,
May 27, 2016, 11:40:05 AM5/27/16
to Elm Discuss
Wow! I didn't know that. 

On Fri, May 27, 2016 at 2:37 AM James Wilson <jam...@gmail.com> wrote:
Correct: Every time the global update function in your app runs for any reason, the global subscriptions object is reevaluated as well, and effect managers receive the new list of current subscriptions.

--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/7iorvKOUjJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.

jonathan de montalembert

unread,
May 31, 2016, 5:18:59 AM5/31/16
to Elm Discuss
I believe that every functions that receive a model are reevaluated when the model changes.
Reply all
Reply to author
Forward
0 new messages