Example of shared model in elm-spa

Could someone point me to the code of an elm-spa app that defines a shared Model used across multiple pages? I’m struggling to follow the docs about where I define a shared model, or if I need to duplicate the model definition in each page.

thanks

1 Like

I don’t have a open source example unfortunatelly.

Create a module src/Shared.elm which will have the shared model. No need to duplicate this in each page.

Then in each page you will get that shared model in init, view, update. e.g.

import Shared

init : Shared.Model -> ...
2 Likes

thank you, Sebastian

With your tip, I was suddenly empowered to find the information in the docs! :slight_smile:

The docs clearly state " By default, an empty Shared.elm file is generated for us in .elm-spa/defaults. When you are ready to share data between pages– move that file from the defaults folder to the src folder." - I should have slowed down and read the section and not scanned it.

1 Like

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