Skip to content
This repository was archived by the owner on Jan 20, 2018. It is now read-only.
This repository was archived by the owner on Jan 20, 2018. It is now read-only.

Initial command obliterates previous state #18

@mattrrichard

Description

@mattrrichard

On start up, my app randomizes its state as part of its init command:

main =
    let 
        startupCmd = 
            Random.generate NewModel modelGenerator
    in
        Html.program
            { init = ( emptyModel, startupCmd )
            , update = update 
            , view = view
            , subscriptions = subscriptions
            }

The problem here is that its NewModel message ticks after the app's previous state is injected.

Is this something that can be worked around by elm-hot-reload? If not, what about a way to signal to the app that it has been hot reloaded? That way I could simply not issue the startup command in those cases. e.g. :

main = 
    let
        startupCmd = 
            Random.generate NewModel modelGenerator

        init flags =
            if flags.hotSwapped then
                ( emptyModel, Cmd.none )
            else
                ( emptyModel, startupCmd )
    in
        Html.programWithFlags
            { init = init
            , update = update startupCmd discoCmd
            , view = view
            , subscriptions = subscriptions
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions