orus-io/elm-spa/1.3.0

NOTE: the latest version is 3.0.1

Spa

Create the application

{ init : flags -> Key -> ( shared, Cmd sharedMsg )
, subscriptions : shared -> Sub sharedMsg
, update : sharedMsg -> shared -> ( shared, Cmd sharedMsg )
, defaultView : view
, toRoute : Url -> route
, extractIdentity : shared -> Maybe identity
, protectPage : route -> String
}
-> Builder flags route identity shared sharedMsg view () () ()

Bootstrap a Spa application

Spa.init
    { init = Shared.init
    , subscriptions = Shared.subscriptions
    , update = Shared.update
    , defaultView = View.defaultView
    , toRoute = Route.toRoute
    , extractIdentity = Shared.identity
    , protectPage = Route.toUrl >> Just >> Route.SignIn >> Route.toUrl
    }
initNoShared : (Url -> route) -> view -> Builder () route () () () view () () ()

Bootstrap a Spa application that has no Shared state

Add pages

( ( currentPageMsg
-> Msg sharedMsg (PageMsg currentPageMsg previousPageMsg)
)
-> pageView
-> view
, ( Msg sharedMsg previousPageMsg
-> Msg sharedMsg (PageMsg currentPageMsg previousPageMsg)
)
-> previousView
-> view
)
-> (route -> Maybe pageFlags)
-> ( shared
-> Page
pageFlags
sharedMsg
pageView
currentPageModel
currentPageMsg
)
flags
route
identity
shared
sharedMsg
previousView
prev
prevprev
previousPageMsg
flags
route
identity
shared
sharedMsg
view
currentPageModel
(PageModel prev prevprev)
(PageMsg currentPageMsg previousPageMsg)

Add a public page to the application

( ( currentPageMsg
-> Msg sharedMsg (PageMsg currentPageMsg previousPageMsg)
)
-> pageView
-> view
, ( Msg sharedMsg previousPageMsg
-> Msg sharedMsg (PageMsg currentPageMsg previousPageMsg)
)
-> previousView
-> view
)
-> (route -> Maybe pageFlags)
-> ( shared
-> identity
-> Page
pageFlags
sharedMsg
pageView
currentPageModel
currentPageMsg
)
flags
route
identity
shared
sharedMsg
previousView
prev
prevprev
previousPageMsg
flags
route
identity
shared
sharedMsg
view
currentPageModel
(PageModel prev prevprev)
(PageMsg currentPageMsg previousPageMsg)

Add a protected page to the application

Finalize

Once all the pages are added to the application, we can change it into a record suitable for the Browser.application function.

{ toDocument : shared -> view -> Document (Msg sharedMsg pageMsg) }
flags
route
identity
shared
sharedMsg
view
current
previous
pageMsg
-> { init :
flags
-> Url
-> Key
-> ( Model route shared current previous
, Cmd (Msg sharedMsg pageMsg)
)
, view :
Model route shared current previous
-> Document (Msg sharedMsg pageMsg)
, update :
Msg sharedMsg pageMsg
-> Model route shared current previous
-> ( Model route shared current previous
, Cmd (Msg sharedMsg pageMsg)
)
, subscriptions :
Model route shared current previous
-> Sub (Msg sharedMsg pageMsg)
, onUrlRequest : UrlRequest -> Msg sharedMsg pageMsg
, onUrlChange : Url -> Msg sharedMsg pageMsg
}

Finalize the Spa application into a record suitable for the Browser.application

toDocument is a function that convert a view to a Browser.Document

appWithPages
    |> Spa.application { toDocument = View.toDocument }
    |> Browser.application
mapSharedMsg : sharedMsg -> Msg sharedMsg pageMsg

map a shared message to top-level application message

Useful to put shared msg events in the 'toDocument' function

Types

type Builder flags route identity shared sharedMsg view current previous pageMsg

Intermediate type for building an application

type Model route shared current previous

The application model

type Msg sharedMsg pageMsg

The top-level application message type

type alias Page flags sharedMsg view model msg =
Page flags sharedMsg view model msg

A page definition

See package Spa.Page for constructors

type PageModel current previous

A model for storing the active page model

type PageMsg current previous

A message type that carries page messages