Renamed to ryan-haskell/elm-spa. It is published under that name, and new versions come out there.
Versions published as ryannhg/elm-spa still install under that name. 13 versions of 13 come from the new location (see their notes).
Rerouted (fork, verified). The original repository is gone. This copy comes from a fork that still has the tag. The Lamdera package server serves a copy recovered from https://github.com/tuohy/elm-spa (a fork).
What we checked: Rebuilt with git archive from commit 292236b2582f of https://github.com/tuohy/elm-spa (a fork) (zip prefix ryannhg-elm-spa-8ee73bf/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 597d34671fca0206517a1cd488d425f4f335b10f.
The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.
Details · package.elm-lang.org's zip: https://github.com/ryannhg/elm-spa/zipball/1.0.0/
Each page can be as simple or complex as you need:
Static - for rendering a simple view
Sandbox - for maintaining state, without any side-effects
Element - for maintaining state, with side-effects
Component - for a full-blown page, that can view and update global state
For rendering a simple view.
page =
Page.static
{ title = title
, view = view
}For maintaining state, without any side-effects.
page =
Page.sandbox
{ title = title
, init = init
, update = update
, view = view
}Create an sandbox page from a record. Here's an example
For maintaining state, with side-effects.
page =
Page.element
{ title = title
, init = init
, update = update
, view = view
, subscriptions = subscriptions
}Create an element page from a record. Here's an example
For a full-blown page, that can view and update global state.
page =
Page.component
{ title = title
, init = init
, update = update
, view = view
, subscriptions = subscriptions
}Create an component page from a record. Here's an example
The rest of this module contains types and functions that can be generated with the cli companion tool
If you're typing this stuff manually, you might need to know what these are for!
A page that is comprimised of smaller pages, that is able to share a common layout (maybe a something like a sidebar!)
page =
Page.layout
{ map = Html.map
, layout = Layout.view
, pages =
{ init = init
, update = update
, bundle = bundle
}
}These are used by top-level files like src/Generated/Pages.elm
to compose together pages and layouts.
We'll get a better understanding of init, update, and bundle below!
Page.layout
{ map = Html.map
, layout = Layout.view
, pages =
{ init = init
, update = update
, bundle = bundle
}
}Implementing the init, update and bundle functions is much easier
when you turn a Page type into Recipe.
A Recipe contains a record waiting for page specific data.
init: just needs a route
upgrade : just needs a msg and model
bundle (view/subscriptions) : just needs a model
We can "bundle" the view and subscriptions functions together,
because they both only depend on the current model. That's why this
API exposes bundle instead of making you type this:
-- BEFORE
view model =
case model_ of
FooModel model ->
foo.view model
BarModel model ->
bar.view model
BazModel model ->
baz.view model
subscriptions model =
case model_ of
FooModel model ->
foo.subscriptions model
BarModel model ->
bar.subscriptions model
BazModel model ->
baz.subscriptions model
-- AFTER
bundle model =
case model_ of
FooModel model ->
foo.bundle model
BarModel model ->
bar.bundle model
BazModel model ->
baz.bundle model(Woohoo, less case expressions to type out!)
Turns a page and some upgrade information into a recipe,
for use in a layout's init, update, and bundle functions!
Page.recipe Homepage.page
{ toModel = HomepageModel
, toMsg = HomepageMsg
, map = Element.map -- ( if using elm-ui )
}In the event that our case expression in update receives a msg that doesn't
match it's model, we use this function to keep the model as-is.
update msg_ model_ =
case ( msg_, model_ ) of
( FooMsg msg, FooModel model ) ->
foo.update msg model
( BarMsg msg, BarModel model ) ->
bar.update msg model
( BazMsg msg, BazModel model ) ->
baz.update msg model
_ ->
Page.keep model_
Create an
staticpage from a record. Here's an example