From 6f855185d029234d6716ffee37c770c1e5619967 Mon Sep 17 00:00:00 2001 From: Ryan Haskell-Glatz Date: Sat, 26 Oct 2019 11:00:58 -0500 Subject: [PATCH] separate routes from pages --- example/src/Generated/Pages.elm | 54 ++++++------------- example/src/Generated/Pages/Settings.elm | 30 +++-------- example/src/Generated/Route.elm | 57 ++++++++++++++++++++ example/src/Generated/Route/Settings.elm | 35 ++++++++++++ example/src/Main.elm | 5 +- example/src/Pages/Counter.elm | 5 -- example/src/Pages/Index.elm | 5 -- example/src/Pages/NotFound.elm | 5 -- example/src/Pages/Random.elm | 5 -- example/src/Pages/Settings/Account.elm | 5 -- example/src/Pages/Settings/Notifications.elm | 6 --- example/src/Pages/Settings/User.elm | 5 -- example/src/Pages/SignIn.elm | 10 ++-- 13 files changed, 122 insertions(+), 105 deletions(-) create mode 100644 example/src/Generated/Route.elm create mode 100644 example/src/Generated/Route/Settings.elm diff --git a/example/src/Generated/Pages.elm b/example/src/Generated/Pages.elm index 759c365..f87d1a6 100644 --- a/example/src/Generated/Pages.elm +++ b/example/src/Generated/Pages.elm @@ -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 diff --git a/example/src/Generated/Pages/Settings.elm b/example/src/Generated/Pages/Settings.elm index 7863716..9d17140 100644 --- a/example/src/Generated/Pages/Settings.elm +++ b/example/src/Generated/Pages/Settings.elm @@ -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 diff --git a/example/src/Generated/Route.elm b/example/src/Generated/Route.elm new file mode 100644 index 0000000..1ceeb94 --- /dev/null +++ b/example/src/Generated/Route.elm @@ -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 + ] diff --git a/example/src/Generated/Route/Settings.elm b/example/src/Generated/Route/Settings.elm new file mode 100644 index 0000000..3d28537 --- /dev/null +++ b/example/src/Generated/Route/Settings.elm @@ -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 + ] diff --git a/example/src/Main.elm b/example/src/Main.elm index ca50564..69813c5 100644 --- a/example/src/Main.elm +++ b/example/src/Main.elm @@ -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 diff --git a/example/src/Pages/Counter.elm b/example/src/Pages/Counter.elm index 2dbab89..99a3155 100644 --- a/example/src/Pages/Counter.elm +++ b/example/src/Pages/Counter.elm @@ -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 diff --git a/example/src/Pages/Index.elm b/example/src/Pages/Index.elm index 8c5675a..af3bcef 100644 --- a/example/src/Pages/Index.elm +++ b/example/src/Pages/Index.elm @@ -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 diff --git a/example/src/Pages/NotFound.elm b/example/src/Pages/NotFound.elm index 8cc8a15..be9d1df 100644 --- a/example/src/Pages/NotFound.elm +++ b/example/src/Pages/NotFound.elm @@ -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 diff --git a/example/src/Pages/Random.elm b/example/src/Pages/Random.elm index c5e9240..06fc717 100644 --- a/example/src/Pages/Random.elm +++ b/example/src/Pages/Random.elm @@ -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 diff --git a/example/src/Pages/Settings/Account.elm b/example/src/Pages/Settings/Account.elm index 052730f..60c48ce 100644 --- a/example/src/Pages/Settings/Account.elm +++ b/example/src/Pages/Settings/Account.elm @@ -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 diff --git a/example/src/Pages/Settings/Notifications.elm b/example/src/Pages/Settings/Notifications.elm index 2b721e7..cb67bc1 100644 --- a/example/src/Pages/Settings/Notifications.elm +++ b/example/src/Pages/Settings/Notifications.elm @@ -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 diff --git a/example/src/Pages/Settings/User.elm b/example/src/Pages/Settings/User.elm index cd92f8f..e0a9f70 100644 --- a/example/src/Pages/Settings/User.elm +++ b/example/src/Pages/Settings/User.elm @@ -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 diff --git a/example/src/Pages/SignIn.elm b/example/src/Pages/SignIn.elm index 946ebea..27976fe 100644 --- a/example/src/Pages/SignIn.elm +++ b/example/src/Pages/SignIn.elm @@ -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