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
Msg
andModel
types 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 page
msg to navigate between each other.
What is the best way to achieve this in Elm?