use page file to make type errors nicer

This commit is contained in:
Ryan Haskell-Glatz 2020-03-28 14:34:19 -05:00
parent f22a7430cb
commit bb2a461a26
8 changed files with 105 additions and 31 deletions

81
example/src/Page.elm Normal file
View File

@ -0,0 +1,81 @@
module Page exposing
( Page, Document, Bundle
, upgrade
, static, sandbox, element, component
)
{-|
@docs Page, Document, Bundle
@docs upgrade
@docs static, sandbox, element, component
-}
import Browser
import Global
import Spa
type alias Document msg =
Browser.Document msg
type alias Page flags model msg =
Spa.Page flags model msg Global.Model Global.Msg
type alias Bundle msg =
Spa.Bundle msg
upgrade :
(pageModel -> model)
-> (pageMsg -> msg)
-> Page pageFlags pageModel pageMsg
->
{ init : pageFlags -> Global.Model -> ( model, Cmd msg, Cmd Global.Msg )
, update : pageMsg -> pageModel -> Global.Model -> ( model, Cmd msg, Cmd Global.Msg )
, bundle : pageModel -> Global.Model -> Bundle msg
}
upgrade =
Spa.upgrade
static : { view : Document msg } -> Page flags () msg
static =
Spa.static
sandbox :
{ init : model
, update : msg -> model -> model
, view : model -> Document msg
}
-> Page flags model msg
sandbox =
Spa.sandbox
element :
{ init : flags -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, view : model -> Document msg
}
-> Page flags model msg
element =
Spa.element
component :
{ init : Global.Model -> flags -> ( model, Cmd msg, Cmd Global.Msg )
, update : Global.Model -> msg -> model -> ( model, Cmd msg, Cmd Global.Msg )
, subscriptions : Global.Model -> model -> Sub msg
, view : Global.Model -> model -> Document msg
}
-> Page flags model msg
component =
Spa.component

View File

@ -5,21 +5,20 @@ module Pages.About exposing
, page
)
import Browser exposing (Document)
import Data.Tab as Tab exposing (Tab)
import Html exposing (..)
import Html.Attributes as Attr exposing (class)
import Html.Events as Events
import Spa exposing (Page)
import Page exposing (Document, Page)
-- PAGE
page : Spa.Page Flags Model Msg globalModel globalMsg
page : Page Flags Model Msg
page =
Spa.sandbox
Page.sandbox
{ init = init
, update = update
, view = view

View File

@ -5,10 +5,9 @@ module Pages.Authors.Dynamic.Posts.Dynamic exposing
, page
)
import Browser exposing (Document)
import Html exposing (..)
import Html.Attributes as Attr exposing (class)
import Spa exposing (Page)
import Page exposing (Document, Page)
type alias Flags =
@ -27,9 +26,9 @@ type alias Msg =
Never
page : Page Flags Model Msg globalModel globalMsg
page : Page Flags Model Msg
page =
Spa.element
Page.element
{ init =
\flags ->
( Model flags.param1 flags.param2

View File

@ -5,10 +5,9 @@ module Pages.NotFound exposing
, page
)
import Browser exposing (Document)
import Html exposing (..)
import Html.Attributes as Attr exposing (class)
import Spa exposing (Page)
import Page exposing (Document, Page)
type alias Flags =
@ -23,14 +22,14 @@ type alias Msg =
Never
page : Page Flags Model Msg globalModel globalMsg
page : Page Flags Model Msg
page =
Spa.static
Page.static
{ view = view
}
view : Document msg
view : Document Msg
view =
{ title = "NotFound"
, body =

View File

@ -5,10 +5,9 @@ module Pages.Posts.Dynamic exposing
, page
)
import Browser exposing (Document)
import Html exposing (..)
import Html.Attributes as Attr exposing (class)
import Spa exposing (Page)
import Page exposing (Document, Page)
type alias Flags =
@ -25,9 +24,9 @@ type alias Msg =
Never
page : Page Flags Model Msg globalModel globalMsg
page : Page Flags Model Msg
page =
Spa.element
Page.element
{ init = \flags -> ( Model flags.param1, Cmd.none )
, update = \_ model -> ( model, Cmd.none )
, subscriptions = \_ -> Sub.none

View File

@ -5,10 +5,9 @@ module Pages.Posts.Top exposing
, page
)
import Browser exposing (Document)
import Html exposing (..)
import Html.Attributes as Attr exposing (class, href)
import Spa exposing (Page)
import Page exposing (Document, Page)
type alias Flags =
@ -23,14 +22,14 @@ type alias Msg =
Never
page : Page Flags Model Msg globalModel globalMsg
page : Page Flags Model Msg
page =
Spa.static
Page.static
{ view = view
}
view : Document msg
view : Document Msg
view =
{ title = "Posts"
, body =

View File

@ -5,23 +5,22 @@ module Pages.Profile exposing
, page
)
import Browser exposing (Document)
import Browser.Navigation as Nav
import Data.User as User exposing (User)
import Global
import Html exposing (..)
import Html.Attributes exposing (alt, class, src)
import Html.Events as Events
import Spa exposing (Page)
import Page exposing (Document, Page)
-- PAGE
page : Spa.Page Flags Model Msg Global.Model Global.Msg
page : Page Flags Model Msg
page =
Spa.component
Page.component
{ init = always init
, update = always update
, subscriptions = always subscriptions

View File

@ -1,9 +1,8 @@
module Pages.Top exposing (Flags, Model, Msg, page)
import Browser exposing (Document)
import Html exposing (..)
import Html.Attributes as Attr exposing (class)
import Spa exposing (Page)
import Page exposing (Document, Page)
type alias Flags =
@ -18,14 +17,14 @@ type alias Msg =
Never
page : Page Flags Model Msg globalModel globalMsg
page : Page Flags Model Msg
page =
Spa.static
Page.static
{ view = view
}
view : Document msg
view : Document Msg
view =
{ title = "Homepage"
, body =