Here's how my Elm app is currently structured:
Types.elm:
import Pages.Login.Types as Login
import Pages.Dashboard.Types as Dashboard
type Page = LoginPage
| DashboardPage
type Msg = LoginMsg Login.Msg
| DashboardMsg Dashboard.Msg
| NavigationStart Page
| NavigationEnd Page
type Model = LoginModel Login.Model
| DashboardModel Dashboard.Model
Login.elm:
import Pages.Login.Types as PageTypes
import Types
view : (PageTypes.Msg -> msg) -> PageTypes.Model -> Html msg
view = -- some code
I'm stuck with the following, seemingly, competing requirements:
- Trying to keep the pages fairly independent of each other, where their
MsgandModeltypes can be reasoned about independently - Making pages aware of each other's existence (at the type-level) so that their view/update functions can emit the
NavigationStart pagemsg to navigate between each other.
What is the best way to achieve this in Elm?
Check out Richard Feldman's single page example repo here. Essentially you have a top level app, that manages each model\view\update per page.