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 module Generated.Pages exposing
( Model ( Model
, Msg , Msg
, Route(..)
, bundle , bundle
, init , init
, routes
, update , update
) )
import Application.Page as Page import Application.Page as Page
import Application.Route as Route
import Generated.Pages.Settings as Settings import Generated.Pages.Settings as Settings
import Generated.Route as Route exposing (Route)
import Global import Global
import Pages.Counter as Counter import Pages.Counter as Counter
import Pages.Index as Index 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 -- MODEL & MSG
@ -69,7 +43,7 @@ type Msg
-- RECIPES -- 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 =
Counter.page Counter.page
{ toModel = CounterModel { 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 =
Index.page Index.page
{ toModel = IndexModel { 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 =
NotFound.page NotFound.page
{ toModel = NotFoundModel { 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 =
Random.page Random.page
{ toModel = RandomModel { 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 =
SignIn.page SignIn.page
{ toModel = SignInModel { 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 =
Settings.page Settings.page
{ toModel = SettingsModel { toModel = SettingsModel
@ -124,22 +98,22 @@ settings =
init : Route -> Page.Init Model Msg Global.Model Global.Msg init : Route -> Page.Init Model Msg Global.Model Global.Msg
init route_ = init route_ =
case route_ of case route_ of
CounterRoute route -> Route.Counter route ->
counter.init route counter.init route
IndexRoute route -> Route.Index route ->
index.init route index.init route
NotFoundRoute route -> Route.NotFound route ->
notFound.init route notFound.init route
RandomRoute route -> Route.Random route ->
random.init route random.init route
SignInRoute route -> Route.SignIn route ->
signIn.init route signIn.init route
SettingsRoute route -> Route.Settings route ->
settings.init route settings.init route
@ -167,10 +141,12 @@ update msg_ model_ =
( SettingsMsg msg, SettingsModel model ) -> ( SettingsMsg msg, SettingsModel model ) ->
settings.update msg model settings.update msg model
_ -> _ ->
Page.keep model_ Page.keep model_
-- BUNDLE -- BUNDLE

View File

@ -1,13 +1,11 @@
module Generated.Pages.Settings exposing module Generated.Pages.Settings exposing
( Model ( Model
, Msg , Msg
, Route
, page , page
, routes
) )
import Application.Page as Application import Application.Page as Application
import Application.Route as Route import Generated.Route.Settings as Route exposing (Route)
import Global import Global
import Html exposing (..) import Html exposing (..)
import Layouts.Settings import Layouts.Settings
@ -16,12 +14,6 @@ import Pages.Settings.Notifications as Notifications
import Pages.Settings.User as User import Pages.Settings.User as User
type Route
= AccountRoute Account.Route
| NotificationsRoute Notifications.Route
| UserRoute User.Route
type Model type Model
= AccountModel Account.Model = AccountModel Account.Model
| NotificationsModel Notifications.Model | NotificationsModel Notifications.Model
@ -46,15 +38,7 @@ page =
} }
routes : List (Route.Route Route) account : Application.Recipe Route.AccountParams Account.Model Account.Msg Model Msg Global.Model Global.Msg a
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 = account =
Account.page Account.page
{ toModel = AccountModel { 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 =
Notifications.page Notifications.page
{ toModel = NotificationsModel { 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 =
User.page User.page
{ toModel = UserModel { toModel = UserModel
@ -81,13 +65,13 @@ user =
init : Route -> Application.Init Model Msg Global.Model Global.Msg init : Route -> Application.Init Model Msg Global.Model Global.Msg
init route_ = init route_ =
case route_ of case route_ of
AccountRoute route -> Route.Account route ->
account.init route account.init route
NotificationsRoute route -> Route.Notifications route ->
notifications.init route notifications.init route
UserRoute route -> Route.User route ->
user.init 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 Application exposing (Application)
import Generated.Pages as Pages import Generated.Pages as Pages
import Generated.Route as Route
import Global import Global
import Layouts.Main import Layouts.Main
@ -10,8 +11,8 @@ main : Application Global.Flags Global.Model Global.Msg Pages.Model Pages.Msg
main = main =
Application.create Application.create
{ routing = { routing =
{ routes = Pages.routes { routes = Route.routes
, notFound = Pages.NotFoundRoute () , notFound = Route.NotFound ()
} }
, global = , global =
{ init = Global.init { init = Global.init

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,6 @@
module Pages.Settings.User exposing module Pages.Settings.User exposing
( Model ( Model
, Msg , Msg
, Route
, page , page
) )
@ -17,10 +16,6 @@ type alias Msg =
Never Never
type alias Route =
()
page = page =
Application.static Application.static
{ view = view { 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 Application.Page as Application
import Html exposing (..) import Html exposing (..)
@ -22,10 +26,6 @@ type Field
| Password | Password
type alias Route =
()
page = page =
Application.sandbox Application.sandbox
{ init = always init { init = always init