Elm-spa - 5 calls for every page update

I’ve put a Debug.log on my app’s page : Shared.Model -> Request.With Params -> Page.With Model Msg function

Each time I navigate, I see five debug messages. I was expecting just one.
It’s impractical for me to post all the app code, but can anyone suggest a likely cause for this that I should check out?

If you look at .elm-spa\generated\Gen\Pages.elm, you will see a function called pages. In one of my toy apps it looks like this:

pages :
    { home_ : Bundle Gen.Params.Home_.Params Pages.Home_.Model Pages.Home_.Msg
    , notFound : Static Gen.Params.NotFound.Params
    , books__id_ : Bundle Gen.Params.Books.Id_.Params Pages.Books.Id_.Model Pages.Books.Id_.Msg
    }
pages =
    { home_ = bundle Pages.Home_.page Model.Home_ Msg.Home_
    , notFound = static Pages.NotFound.view Model.NotFound
    , books__id_ = bundle Pages.Books.Id_.page Model.Books__Id_ Msg.Books__Id_
    }

Since pages is a function, it is revaluated each time it is referenced: Pages.Home_.page is evaluated everywhere we use pages in the module.

In practice, pages will be accessed when setting up a Page’s init, view, update and subscriptions.

init : Route -> Shared.Model -> Url -> Key -> ( Model, Effect Msg )
init route =
    case route of
        Route.Home_ ->
            pages.home_.init ()  -- (1)
        ...


update : Msg -> Model -> Shared.Model -> Url -> Key -> ( Model, Effect Msg )
update msg_ model_ =
    case ( msg_, model_ ) of
        ( Msg.Home_ msg, Model.Home_ params model ) ->
            pages.home_.update params msg model   -- (2)
         ...

view : Model -> Shared.Model -> Url -> Key -> View Msg
view model_ =
    case model_ of    
        Model.Home_ params model ->
            pages.home_.view params model  -- (3)
        ...

subscriptions : Model -> Shared.Model -> Url -> Key -> Sub Msg
subscriptions model_ =
    case model_ of
        Model.Home_ params model ->
            pages.home_.subscriptions params model   -- (4)
         ...
3 Likes

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