ryannhg/elm-spa/1.0.0

NOTE: the latest version is 6.0.0

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/

Application

Let's build some single page applications!

Application.create replaces Browser.application as the entrypoint to your app.

module Main exposing (main)


import Application
import Generated.Pages as Pages
import Generated.Route as Route
import Global


main =
    Application.create
        { ui = Application.usingHtml
        , routing =
            { routes = Route.routes
            , toPath = Route.toPath
            , notFound = Route.NotFound ()
            }
        , global =
            { init = Global.init
            , update = Global.update
            , subscriptions = Global.subscriptions
            }
        , page = Pages.page
        }
type alias Program flags globalModel globalMsg layoutModel layoutMsg =
Program
flags
(Model flags globalModel layoutModel)
(Msg globalMsg layoutMsg)

An alias for Platform.Program to make annotations a little more clear.

{ ui :
{ toHtml : uiMsg -> Html (Msg globalMsg layoutMsg)
, map : (layoutMsg -> Msg globalMsg layoutMsg) -> uiLayoutMsg -> uiMsg
}
, routing :
{ routes : List (Route route)
, toPath : route -> String
, notFound : route
}
, global :
{ init :
{ navigate : route -> Cmd (Msg globalMsg layoutMsg) }
-> flags
-> ( globalModel, Cmd globalMsg, Cmd (Msg globalMsg layoutMsg) )
, update :
{ navigate : route -> Cmd (Msg globalMsg layoutMsg) }
-> globalMsg
-> globalModel
-> ( globalModel, Cmd globalMsg, Cmd (Msg globalMsg layoutMsg) )
, subscriptions : globalModel -> Sub globalMsg
}
, page :
Page
route
layoutModel
layoutMsg
uiLayoutMsg
layoutModel
layoutMsg
uiLayoutMsg
globalModel
globalMsg
(Msg globalMsg layoutMsg)
uiMsg
}
-> Program flags globalModel globalMsg layoutModel layoutMsg

Creates a new Program given some one-time configuration:

  • ui - How do we convert the view to Html msg?
  • routing - What are the app's routes?
  • global - How do we manage shared state between pages?
  • page - What pages do we have available?

Supports more than elm/html

If you're a fan of mdgriffith/elm-ui, it's important to support using Element msg instead of Html msg for your pages and components.

Let Application.create know about this by passing in your own Options like these:

import Element
-- other imports


Application.create
    { ui =
        { toHtml = Element.layout []
        , map = Element.map
        }
    , -- ... the rest of your app
    }
{ map :
(layoutMsg -> Msg globalMsg layoutMsg)
-> Html layoutMsg
-> Html (Msg globalMsg layoutMsg)
, toHtml : uiMsg -> uiMsg
}

Pass this in when calling Application.create

( It will work if your view returns the standard Html msg )