Page lifecycle abstraction.
Pages are values, not modules. You can create them with different complexity levels, pass them around, and compose them.
-- Simplest: view-only, no state
aboutPage =
Page.static
{ view = \shared -> Html.text "About"
}
-- With local state:
counterPage =
Page.sandbox
{ init = \shared -> 0
, update = \msg model -> model + 1
, view = \shared model -> Html.text (String.fromInt model)
}
-- Full page with commands:
blogPage =
Page.element
{ init = \shared -> ( Loading, fetchPosts shared.apiUrl )
, update = \msg model -> ( model, Cmd.none )
, view = \shared model -> Html.text "Blog"
, subscriptions = \shared model -> Sub.none
}The loading state of a page, used for transition support.
Create a static page with only a view function. No model, no messages, no update logic.
aboutPage =
Page.static
{ view = \shared -> Html.div [] [ Html.text "About us" ]
}Create a sandbox page with local state but no commands.
counterPage =
Page.sandbox
{ init = \shared -> 0
, update = \msg model -> model + 1
, view = \shared model -> Html.text (String.fromInt model)
}Create a full page with commands and subscriptions.
blogPage =
Page.element
{ init = \shared -> ( initialModel, loadPosts )
, update = updateBlog
, view = viewBlog
, subscriptions = \shared model -> Time.every 60000 Tick
}Map over a page's message type.
Map over a page's model type.
Map over both a page's model and message types. This is the primary way to wire a page into the application's unified model/msg types.
App.page homeSpec =
Page.mapBoth HomeModel HomeMsg (\(HomeMsg m) -> m) (\(HomeModel m) -> m) homePageMore commonly used through the App.page helper.
Get the update function from a page.
Get the subscriptions function from a page.
An opaque page type. Internally normalizes all page variants to the full init/update/view/subscriptions shape.
Type parameters:
shared: the shared state type passed to all page functionsmodel: this page's local modelmsg: this page's message type