From 9e8659b30569b2d4eaf54ea66c4ddd067416c262 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 22:38:57 -0700 Subject: [PATCH] Remove toMsg and toGlobalMsg and change msg type for rendered document. --- examples/docs/src/Global.elm | 23 +++++++--- examples/docs/src/Main.elm | 6 +-- examples/docs/src/Template.elm | 42 +++++++------------ examples/docs/src/Template/BlogIndex.elm | 12 +++--- examples/docs/src/Template/BlogPost.elm | 13 +++--- examples/docs/src/Template/Documentation.elm | 22 ++++++---- examples/docs/src/Template/Page.elm | 14 +++---- examples/docs/src/Template/Showcase.elm | 12 +++--- examples/docs/src/TemplateDocument.elm | 4 +- .../src/generate-template-module-connector.js | 8 ++-- 10 files changed, 76 insertions(+), 80 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index f9b5fd5f..b1cf2bb6 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -27,14 +27,27 @@ type alias Model = } -type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Never) ) +map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 +map fn doc = + { title = doc.title + , body = Element.map fn doc.body + } -type alias RenderedBody msg = + +--mapRendered : (msg1 -> msg2) -> RenderedBody msg1 -> RenderedBody msg2 +--mapRendered fn ( first, second ) = +-- ( first, second |> List.map (Element.map fn) ) + + +type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) +type alias RenderedBody = + ( MarkdownRenderer.TableOfContents, List (Element Never) ) + + type alias PageView msg = { title : String, body : Element msg } @@ -84,7 +97,7 @@ view : -> { a | path : PagePath Pages.PathKey } -> Model -> (Msg -> msg) - -> PageView Never + -> PageView msg -> { body : Html msg, title : String } view stars page model toMsg pageView = { body = @@ -106,7 +119,7 @@ view stars page model toMsg pageView = Element.column [ Element.width Element.fill ] [ header stars page.path |> Element.map toMsg , incrementView model |> Element.map toMsg - , pageView.body |> Element.map never + , pageView.body ] ) |> Element.layout diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index c9657c29..6d8b3d78 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -48,11 +48,7 @@ manifest = } -type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Msg) ) - - -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.View +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.RenderedBody main = TemplateDemultiplexer.mainTemplate { documents = diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index c62930bb..51391a62 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -8,9 +8,7 @@ import Pages.StaticHttp as StaticHttp simplest : { view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> () -> templateMetadata -> renderedTemplate @@ -20,12 +18,12 @@ simplest : -> templateMetadata -> List (Head.Tag pathKey) } - -> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata simplest config = template { view = - \toMsg toGlobalMsg allMetadata () model blogPost rendered -> - config.view toMsg toGlobalMsg allMetadata model blogPost rendered + \allMetadata () model blogPost rendered -> + config.view allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) @@ -37,9 +35,7 @@ simplest config = simpler : { view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateModel -> templateMetadata -> renderedTemplate @@ -51,12 +47,12 @@ simpler : , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata simpler config = template { view = - \toMsg toGlobalMsg allMetadata () model blogPost rendered -> - config.view toMsg toGlobalMsg allMetadata model blogPost rendered + \allMetadata () model blogPost rendered -> + config.view allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init @@ -71,9 +67,7 @@ stateless : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateMetadata -> renderedTemplate @@ -84,12 +78,12 @@ stateless : -> templateMetadata -> List (Head.Tag pathKey) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata stateless config = template { view = - \toMsg toGlobalMsg allMetadata staticData () blogPost rendered -> - config.view toMsg toGlobalMsg allMetadata staticData blogPost rendered + \allMetadata staticData () blogPost rendered -> + config.view allMetadata staticData blogPost rendered , head = config.head , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) @@ -104,9 +98,7 @@ template : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata @@ -122,19 +114,17 @@ template : , save : templateModel -> Global.Model -> Global.Model , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata template config = config -type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg = +type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = { staticData : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 50fed074..ca59a0c8 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -21,7 +21,7 @@ type Msg = Msg -template : TemplateDocument BlogIndex StaticData Model Msg msg +template : TemplateDocument BlogIndex StaticData Model Msg template = Template.template { view = view @@ -77,15 +77,13 @@ type alias View msg = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata static model metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 93364b9d..0de077ee 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -30,7 +30,7 @@ type Msg = Msg -template : TemplateDocument BlogPost () Model Msg msg +template : TemplateDocument BlogPost () Model Msg template = Template.simpler { view = view @@ -98,14 +98,12 @@ update metadata msg model = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> Model -> BlogPost - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata model blogPost rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata model blogPost rendered = { title = blogPost.title , body = Element.column [ Element.width Element.fill ] @@ -132,6 +130,7 @@ view toMsg toGlobalMsg allMetadata model blogPost rendered = :: Palette.blogHeading blogPost.title :: articleImageView blogPost.image :: Tuple.second rendered + |> List.map (Element.map never) ) ] } diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 26d0f08d..46ce10e5 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -32,7 +32,7 @@ type Msg = Msg -template : TemplateDocument Documentation StaticData Model Msg msg +template : TemplateDocument Documentation StaticData Model Msg template = Template.template { view = view @@ -95,19 +95,18 @@ head static currentPath meta = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Documentation - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata static model metadata rendered = { title = metadata.title , body = [ Element.row [] - [ DocSidebar.view + [ counterView model + , DocSidebar.view Pages.pages.index allMetadata |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] @@ -120,7 +119,7 @@ view toMsg toGlobalMsg allMetadata static model metadata rendered = , Element.spacing 30 , Element.Region.mainContent ] - (Tuple.second rendered) + (Tuple.second rendered |> List.map (Element.map never)) ] ] ] @@ -132,6 +131,11 @@ view toMsg toGlobalMsg allMetadata static model metadata rendered = } +counterView : Model -> Element Msg +counterView model = + Element.text "" + + tocView : MarkdownRenderer.TableOfContents -> Element msg tocView toc = Element.column [ Element.alignTop, Element.spacing 20 ] diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index d2d09cbe..60e2dbe6 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -28,7 +28,7 @@ type Msg = Msg -template : TemplateDocument Page StaticData Model Msg msg +template : TemplateDocument Page StaticData Model Msg template = Template.simplest { view = view @@ -76,14 +76,12 @@ head currentPath meta = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> Model -> Page - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata model metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata model metadata rendered = { title = metadata.title , body = [ Element.column @@ -91,7 +89,7 @@ view toMsg toGlobalMsg allMetadata model metadata rendered = , Element.spacing 60 , Element.Region.mainContent ] - (Tuple.second rendered) + (Tuple.second rendered |> List.map (Element.map never)) ] |> Element.textColumn [ Element.width Element.fill diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index bcc491a4..c2f2455d 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -23,7 +23,7 @@ type Msg = Msg -template : TemplateDocument Showcase StaticData Model Msg msg +template : TemplateDocument Showcase StaticData Model Msg template = Template.stateless { view = view @@ -47,14 +47,12 @@ type alias StaticData = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Showcase - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata static metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm index b8486aa5..3278b8d3 100644 --- a/examples/docs/src/TemplateDocument.elm +++ b/examples/docs/src/TemplateDocument.elm @@ -18,5 +18,5 @@ type alias RenderedBody msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg internalMsg = - Template Pages.PathKey templateMetadata (RenderedBody Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata internalMsg +type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg = + Template Pages.PathKey templateMetadata Global.RenderedBody templateStaticData templateModel (View templateMsg) templateMsg GlobalMetadata.Metadata diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 7195dcad..98075332 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -60,7 +60,7 @@ view : } -> StaticHttp.Request - { view : Model -> Global.View -> { title : String, body : Html Msg } + { view : Model -> Global.RenderedBody -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -74,8 +74,6 @@ view siteMetadata page = case model.page of Model${name} subModel -> Template.${name}.template.view - Msg${name} - MsgGlobal siteMetadata data subModel @@ -87,7 +85,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map Msg${name} + ) ) _ ->