Subscriptions: a misunderstanding or a bug?

I created an application were subscriptions were not firing when running the app in Reactor or compiled. The app does work as expected in Ellie.

type Model
    = Empty
    | Running Time.Posix

A Model starts Empty and becomes Running after a Task is performed. After
becoming Running the Running subscriptions branch is called but the subscription is not run – not until another event is fired such as click event.


init : () -> ( Model, Cmd Msg )
init _ =
    ( Empty, Task.perform Tick Time.now )

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Noop ->
            ( model, Cmd.none )

        Tick t ->
            ( Running t, Cmd.none )

subscriptions : Model -> Sub Msg
subscriptions model =
    case model of
        Empty ->
            Sub.none

        Running _ ->
            Time.every 100 Tick

This is the behaviour at least on MacOS Chrome and Safari running the code through Reactor or a complied index.html.

But the behaviour in Ellie is what I would expect when the Running subscriptions branch is reached after initialization.

Here is the code running in Ellie
https://ellie-app.com/ccVCwW7bL2Xa1

So, is this a bug, or I am misunderstanding something about subscriptions?

1 Like

I don’t remember well, but I think it is a known bug. If that were true, you will have to find a workaround.

It sounds like locally you may have a older version of elm/core, there was a fix in 1.0.3 that should have addressed that issue, and might explain why it works in the Ellie (it is using 1.0.5).

Check out Changes in subscriptions without effect if model changes in response to command from init · Issue #1776 · elm/compiler · GitHub

4 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.