mirror of
https://github.com/ryannhg/elm-spa.git
synced 2024-11-22 01:32:43 +03:00
update cli to support simpler api
This commit is contained in:
parent
bb2a461a26
commit
7e419459a5
2
cli/package-lock.json
generated
2
cli/package-lock.json
generated
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "elm-spa",
|
||||
"version": "4.0.4",
|
||||
"version": "4.0.5",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "elm-spa",
|
||||
"version": "4.0.4",
|
||||
"version": "4.0.5",
|
||||
"description": "single page apps made easy",
|
||||
"main": "index.js",
|
||||
"bin": "./index.js",
|
||||
|
@ -23,6 +23,6 @@
|
||||
"concurrently": "5.0.0",
|
||||
"elm": "0.19.1-3",
|
||||
"elm-live": "4.0.2",
|
||||
"elm-spa": "4.0.4"
|
||||
"elm-spa": "4.0.5"
|
||||
}
|
||||
}
|
||||
|
81
cli/projects/new/src/Page.elm
Normal file
81
cli/projects/new/src/Page.elm
Normal 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
|
@ -1,9 +1,7 @@
|
||||
module Pages.Docs exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -18,9 +16,9 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.static
|
||||
Page.static
|
||||
{ view = view
|
||||
}
|
||||
|
||||
@ -29,4 +27,4 @@ view : Document Msg
|
||||
view =
|
||||
{ title = "Docs"
|
||||
, body = [ Html.text "Docs" ]
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
module Pages.NotFound exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -18,9 +16,9 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.static
|
||||
Page.static
|
||||
{ view = view
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
module Pages.Top exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -18,9 +16,9 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.static
|
||||
Page.static
|
||||
{ view = view
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,9 @@ create path =
|
||||
"""
|
||||
module Pages.{{name}} exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -26,9 +25,9 @@ type Msg
|
||||
= NoOp
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.component
|
||||
Page.component
|
||||
{ init = init
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
|
@ -8,10 +8,8 @@ create path =
|
||||
"""
|
||||
module Pages.{{name}} exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -26,9 +24,9 @@ type Msg
|
||||
= NoOp
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.element
|
||||
Page.element
|
||||
{ init = init
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
|
@ -8,10 +8,8 @@ create path =
|
||||
"""
|
||||
module Pages.{{name}} exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -26,9 +24,9 @@ type Msg
|
||||
= NoOp
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.sandbox
|
||||
Page.sandbox
|
||||
{ init = init
|
||||
, update = update
|
||||
, view = view
|
||||
|
@ -8,10 +8,8 @@ create path =
|
||||
"""
|
||||
module Pages.{{name}} exposing (Flags, Model, Msg, page)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Global
|
||||
import Html
|
||||
import Spa
|
||||
import Page exposing (Document, Page)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -26,9 +24,9 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Spa.Page Flags Model Msg Global.Model Global.Msg
|
||||
page : Page Flags Model Msg
|
||||
page =
|
||||
Spa.static
|
||||
Page.static
|
||||
{ view = view
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,9 @@ module Generated.Pages exposing
|
||||
, view
|
||||
)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Generated.Route as Route exposing (Route)
|
||||
import Global
|
||||
import Spa
|
||||
import Page exposing (Bundle, Document)
|
||||
{{pagesImports}}
|
||||
|
||||
|
||||
@ -49,7 +48,7 @@ import Spa
|
||||
type alias UpgradedPage flags model msg =
|
||||
{ init : flags -> Global.Model -> ( Model, Cmd Msg, Cmd Global.Msg )
|
||||
, update : msg -> model -> Global.Model -> ( Model, Cmd Msg, Cmd Global.Msg )
|
||||
, bundle : model -> Global.Model -> Spa.Bundle Msg
|
||||
, bundle : model -> Global.Model -> Bundle Msg
|
||||
}
|
||||
|
||||
|
||||
@ -171,7 +170,7 @@ pagesUpgradedValues paths =
|
||||
( Path.toVariableName path
|
||||
, "Pages."
|
||||
++ Path.toModulePath path
|
||||
++ ".page |> Spa.upgrade "
|
||||
++ ".page |> Page.upgrade "
|
||||
++ Path.toTypeName path
|
||||
++ "_Model "
|
||||
++ Path.toTypeName path
|
||||
@ -258,7 +257,7 @@ pagesBundle : List Path -> String
|
||||
pagesBundle paths =
|
||||
Utils.function
|
||||
{ name = "bundle"
|
||||
, annotation = [ "Model", "Global.Model", "Spa.Bundle Msg" ]
|
||||
, annotation = [ "Model", "Global.Model", "Bundle Msg" ]
|
||||
, inputs = [ "bigModel" ]
|
||||
, body =
|
||||
Utils.caseExpression
|
||||
|
@ -96,17 +96,17 @@ type Model
|
||||
\_ ->
|
||||
paths.single
|
||||
|> Pages.pagesUpgradedValues
|
||||
|> Expect.equal " { top = Pages.Top.page |> Spa.upgrade Top_Model Top_Msg }"
|
||||
|> Expect.equal " { top = Pages.Top.page |> Page.upgrade Top_Model Top_Msg }"
|
||||
, test "works with multiple paths" <|
|
||||
\_ ->
|
||||
paths.multiple
|
||||
|> Pages.pagesUpgradedValues
|
||||
|> Expect.equal """ { top = Pages.Top.page |> Spa.upgrade Top_Model Top_Msg
|
||||
, about = Pages.About.page |> Spa.upgrade About_Model About_Msg
|
||||
, notFound = Pages.NotFound.page |> Spa.upgrade NotFound_Model NotFound_Msg
|
||||
, posts_top = Pages.Posts.Top.page |> Spa.upgrade Posts_Top_Model Posts_Top_Msg
|
||||
, posts_dynamic = Pages.Posts.Dynamic.page |> Spa.upgrade Posts_Dynamic_Model Posts_Dynamic_Msg
|
||||
, authors_dynamic_posts_dynamic = Pages.Authors.Dynamic.Posts.Dynamic.page |> Spa.upgrade Authors_Dynamic_Posts_Dynamic_Model Authors_Dynamic_Posts_Dynamic_Msg
|
||||
|> Expect.equal """ { top = Pages.Top.page |> Page.upgrade Top_Model Top_Msg
|
||||
, about = Pages.About.page |> Page.upgrade About_Model About_Msg
|
||||
, notFound = Pages.NotFound.page |> Page.upgrade NotFound_Model NotFound_Msg
|
||||
, posts_top = Pages.Posts.Top.page |> Page.upgrade Posts_Top_Model Posts_Top_Msg
|
||||
, posts_dynamic = Pages.Posts.Dynamic.page |> Page.upgrade Posts_Dynamic_Model Posts_Dynamic_Msg
|
||||
, authors_dynamic_posts_dynamic = Pages.Authors.Dynamic.Posts.Dynamic.page |> Page.upgrade Authors_Dynamic_Posts_Dynamic_Model Authors_Dynamic_Posts_Dynamic_Msg
|
||||
}"""
|
||||
]
|
||||
, describe "pagesInit"
|
||||
@ -196,7 +196,7 @@ update bigMsg bigModel =
|
||||
paths.single
|
||||
|> Pages.pagesBundle
|
||||
|> Expect.equal (String.trim """
|
||||
bundle : Model -> Global.Model -> Spa.Bundle Msg
|
||||
bundle : Model -> Global.Model -> Bundle Msg
|
||||
bundle bigModel =
|
||||
case bigModel of
|
||||
Top_Model model ->
|
||||
@ -207,7 +207,7 @@ bundle bigModel =
|
||||
paths.multiple
|
||||
|> Pages.pagesBundle
|
||||
|> Expect.equal (String.trim """
|
||||
bundle : Model -> Global.Model -> Spa.Bundle Msg
|
||||
bundle : Model -> Global.Model -> Bundle Msg
|
||||
bundle bigModel =
|
||||
case bigModel of
|
||||
Top_Model model ->
|
||||
|
Loading…
Reference in New Issue
Block a user