separate routes from pages

This commit is contained in:
Ryan Haskell-Glatz 2019-10-26 11:00:58 -05:00
parent 1f24414e2e
commit 6f855185d0
13 changed files with 122 additions and 105 deletions

View File

@ -1,16 +1,14 @@
module Generated.Pages exposing
( Model
, Msg
, Route(..)
, bundle
, init
, routes
, update
)
import Application.Page as Page
import Application.Route as Route
import Generated.Pages.Settings as Settings
import Generated.Route as Route exposing (Route)
import Global
import Pages.Counter as Counter
import Pages.Index as Index
@ -20,30 +18,6 @@ import Pages.SignIn as SignIn
-- ROUTES
type Route
= CounterRoute Counter.Route
| IndexRoute Index.Route
| NotFoundRoute NotFound.Route
| RandomRoute Random.Route
| SignInRoute SignIn.Route
| SettingsRoute Settings.Route
routes : List (Route.Route Route)
routes =
[ Route.path "counter" CounterRoute
, Route.index IndexRoute
, Route.path "not-found" NotFoundRoute
, Route.path "random" RandomRoute
, Route.path "sign-in" SignInRoute
, Route.folder "settings" SettingsRoute Settings.routes
]
-- MODEL & MSG
@ -69,7 +43,7 @@ type Msg
-- RECIPES
counter : Page.Recipe Counter.Route Counter.Model Counter.Msg Model Msg Global.Model Global.Msg a
counter : Page.Recipe Route.CounterParams Counter.Model Counter.Msg Model Msg Global.Model Global.Msg a
counter =
Counter.page
{ toModel = CounterModel
@ -77,7 +51,7 @@ counter =
}
index : Page.Recipe Index.Route Index.Model Index.Msg Model Msg Global.Model Global.Msg a
index : Page.Recipe Route.IndexParams Index.Model Index.Msg Model Msg Global.Model Global.Msg a
index =
Index.page
{ toModel = IndexModel
@ -85,7 +59,7 @@ index =
}
notFound : Page.Recipe NotFound.Route NotFound.Model NotFound.Msg Model Msg Global.Model Global.Msg a
notFound : Page.Recipe Route.NotFoundParams NotFound.Model NotFound.Msg Model Msg Global.Model Global.Msg a
notFound =
NotFound.page
{ toModel = NotFoundModel
@ -93,7 +67,7 @@ notFound =
}
random : Page.Recipe Random.Route Random.Model Random.Msg Model Msg Global.Model Global.Msg a
random : Page.Recipe Route.RandomParams Random.Model Random.Msg Model Msg Global.Model Global.Msg a
random =
Random.page
{ toModel = RandomModel
@ -101,7 +75,7 @@ random =
}
signIn : Page.Recipe SignIn.Route SignIn.Model SignIn.Msg Model Msg Global.Model Global.Msg a
signIn : Page.Recipe Route.SignInParams SignIn.Model SignIn.Msg Model Msg Global.Model Global.Msg a
signIn =
SignIn.page
{ toModel = SignInModel
@ -109,7 +83,7 @@ signIn =
}
settings : Page.Recipe Settings.Route Settings.Model Settings.Msg Model Msg Global.Model Global.Msg a
settings : Page.Recipe Route.SettingsParams Settings.Model Settings.Msg Model Msg Global.Model Global.Msg a
settings =
Settings.page
{ toModel = SettingsModel
@ -124,22 +98,22 @@ settings =
init : Route -> Page.Init Model Msg Global.Model Global.Msg
init route_ =
case route_ of
CounterRoute route ->
Route.Counter route ->
counter.init route
IndexRoute route ->
Route.Index route ->
index.init route
NotFoundRoute route ->
Route.NotFound route ->
notFound.init route
RandomRoute route ->
Route.Random route ->
random.init route
SignInRoute route ->
Route.SignIn route ->
signIn.init route
SettingsRoute route ->
Route.Settings route ->
settings.init route
@ -167,10 +141,12 @@ update msg_ model_ =
( SettingsMsg msg, SettingsModel model ) ->
settings.update msg model
_ ->
Page.keep model_
-- BUNDLE

View File

@ -1,13 +1,11 @@
module Generated.Pages.Settings exposing
( Model
, Msg
, Route
, page
, routes
)
import Application.Page as Application
import Application.Route as Route
import Generated.Route.Settings as Route exposing (Route)
import Global
import Html exposing (..)
import Layouts.Settings
@ -16,12 +14,6 @@ import Pages.Settings.Notifications as Notifications
import Pages.Settings.User as User
type Route
= AccountRoute Account.Route
| NotificationsRoute Notifications.Route
| UserRoute User.Route
type Model
= AccountModel Account.Model
| NotificationsModel Notifications.Model
@ -46,15 +38,7 @@ page =
}
routes : List (Route.Route Route)
routes =
[ Route.path "account" AccountRoute
, Route.path "notifications" NotificationsRoute
, Route.path "user" UserRoute
]
account : Application.Recipe Account.Route Account.Model Account.Msg Model Msg Global.Model Global.Msg a
account : Application.Recipe Route.AccountParams Account.Model Account.Msg Model Msg Global.Model Global.Msg a
account =
Account.page
{ toModel = AccountModel
@ -62,7 +46,7 @@ account =
}
notifications : Application.Recipe Notifications.Route Notifications.Model Notifications.Msg Model Msg Global.Model Global.Msg a
notifications : Application.Recipe Route.NotificationsParams Notifications.Model Notifications.Msg Model Msg Global.Model Global.Msg a
notifications =
Notifications.page
{ toModel = NotificationsModel
@ -70,7 +54,7 @@ notifications =
}
user : Application.Recipe User.Route User.Model User.Msg Model Msg Global.Model Global.Msg a
user : Application.Recipe Route.UserParams User.Model User.Msg Model Msg Global.Model Global.Msg a
user =
User.page
{ toModel = UserModel
@ -81,13 +65,13 @@ user =
init : Route -> Application.Init Model Msg Global.Model Global.Msg
init route_ =
case route_ of
AccountRoute route ->
Route.Account route ->
account.init route
NotificationsRoute route ->
Route.Notifications route ->
notifications.init route
UserRoute route ->
Route.User route ->
user.init route

View File

@ -0,0 +1,57 @@
module Generated.Route exposing
( CounterParams
, IndexParams
, NotFoundParams
, RandomParams
, Route(..)
, SettingsParams
, SignInParams
, routes
)
import Application.Route as Route
import Generated.Route.Settings as Settings
type alias CounterParams =
()
type alias IndexParams =
()
type alias NotFoundParams =
()
type alias RandomParams =
()
type alias SignInParams =
()
type alias SettingsParams =
Settings.Route
type Route
= Counter CounterParams
| Index IndexParams
| NotFound NotFoundParams
| Random RandomParams
| SignIn SignInParams
| Settings SettingsParams
routes : List (Route.Route Route)
routes =
[ Route.path "counter" Counter
, Route.index Index
, Route.path "not-found" NotFound
, Route.path "random" Random
, Route.path "sign-in" SignIn
, Route.folder "settings" Settings Settings.routes
]

View File

@ -0,0 +1,35 @@
module Generated.Route.Settings exposing
( AccountParams
, NotificationsParams
, Route(..)
, UserParams
, routes
)
import Application.Route as Route
type alias AccountParams =
()
type alias NotificationsParams =
()
type alias UserParams =
()
type Route
= Account AccountParams
| Notifications NotificationsParams
| User UserParams
routes : List (Route.Route Route)
routes =
[ Route.path "account" Account
, Route.path "notifications" Notifications
, Route.path "user" User
]

View File

@ -2,6 +2,7 @@ module Main exposing (main)
import Application exposing (Application)
import Generated.Pages as Pages
import Generated.Route as Route
import Global
import Layouts.Main
@ -10,8 +11,8 @@ main : Application Global.Flags Global.Model Global.Msg Pages.Model Pages.Msg
main =
Application.create
{ routing =
{ routes = Pages.routes
, notFound = Pages.NotFoundRoute ()
{ routes = Route.routes
, notFound = Route.NotFound ()
}
, global =
{ init = Global.init

View File

@ -1,7 +1,6 @@
module Pages.Counter exposing
( Model
, Msg
, Route
, page
)
@ -21,10 +20,6 @@ type Msg
| Decrement
type alias Route =
()
page =
Application.sandbox
{ init = always init

View File

@ -1,7 +1,6 @@
module Pages.Index exposing
( Model
, Msg
, Route
, page
)
@ -18,10 +17,6 @@ type alias Msg =
Never
type alias Route =
()
page =
Application.static
{ view = view

View File

@ -1,7 +1,6 @@
module Pages.NotFound exposing
( Model
, Msg
, Route
, page
)
@ -17,10 +16,6 @@ type alias Msg =
Never
type alias Route =
()
page =
Application.static
{ view = view

View File

@ -1,7 +1,6 @@
module Pages.Random exposing
( Model
, Msg
, Route
, page
)
@ -23,10 +22,6 @@ type Msg
| CatResponded (Result Http.Error String)
type alias Route =
()
page =
Application.element
{ init = always init

View File

@ -1,7 +1,6 @@
module Pages.Settings.Account exposing
( Model
, Msg
, Route
, page
)
@ -17,10 +16,6 @@ type alias Msg =
Never
type alias Route =
()
page =
Application.static
{ view = view

View File

@ -1,12 +1,10 @@
module Pages.Settings.Notifications exposing
( Model
, Msg
, Route
, page
)
import Application.Page as Application
import Global
import Html exposing (..)
@ -18,10 +16,6 @@ type alias Msg =
Never
type alias Route =
()
page =
Application.static
{ view = view

View File

@ -1,7 +1,6 @@
module Pages.Settings.User exposing
( Model
, Msg
, Route
, page
)
@ -17,10 +16,6 @@ type alias Msg =
Never
type alias Route =
()
page =
Application.static
{ view = view

View File

@ -1,4 +1,8 @@
module Pages.SignIn exposing (Model, Msg, Route, page)
module Pages.SignIn exposing
( Model
, Msg
, page
)
import Application.Page as Application
import Html exposing (..)
@ -22,10 +26,6 @@ type Field
| Password
type alias Route =
()
page =
Application.sandbox
{ init = always init