mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-05 12:57:33 +03:00
Wire in subscriptions for templates.
This commit is contained in:
parent
86da9973bd
commit
e71e90172a
@ -25,7 +25,7 @@ main =
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
, site = Site.config
|
, site = Site.config
|
||||||
, subscriptions = \_ -> Sub.none
|
, subscriptions = Sub.none
|
||||||
}
|
}
|
||||||
|> RssPlugin.generate
|
|> RssPlugin.generate
|
||||||
{ siteTagline = Site.tagline
|
{ siteTagline = Site.tagline
|
||||||
|
@ -29,6 +29,7 @@ sandbox config =
|
|||||||
, staticData = \_ -> StaticHttp.succeed ()
|
, staticData = \_ -> StaticHttp.succeed ()
|
||||||
, init = \_ -> ( (), Cmd.none )
|
, init = \_ -> ( (), Cmd.none )
|
||||||
, update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp )
|
, update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp )
|
||||||
|
, subscriptions = \_ _ _ -> Sub.none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,9 +56,12 @@ simpler config =
|
|||||||
, staticData = \_ -> StaticHttp.succeed ()
|
, staticData = \_ -> StaticHttp.succeed ()
|
||||||
, init = config.init
|
, init = config.init
|
||||||
, update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Shared.NoOp ))
|
, update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Shared.NoOp ))
|
||||||
|
, subscriptions = \_ _ _ -> Sub.none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{-| Basic `staticData` (including access to Shared static data)
|
||||||
|
-}
|
||||||
stateless :
|
stateless :
|
||||||
{ staticData :
|
{ staticData :
|
||||||
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
|
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
|
||||||
@ -81,9 +85,12 @@ stateless config =
|
|||||||
, staticData = config.staticData
|
, staticData = config.staticData
|
||||||
, init = \_ -> ( (), Cmd.none )
|
, init = \_ -> ( (), Cmd.none )
|
||||||
, update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp )
|
, update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp )
|
||||||
|
, subscriptions = \_ _ _ -> Sub.none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{-| Full application (including local `Model`, `Msg`, `update`)
|
||||||
|
-}
|
||||||
application :
|
application :
|
||||||
{ staticData :
|
{ staticData :
|
||||||
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
|
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
|
||||||
@ -99,6 +106,7 @@ application :
|
|||||||
-> List (Head.Tag Pages.PathKey)
|
-> List (Head.Tag Pages.PathKey)
|
||||||
, init : templateMetadata -> ( templateModel, Cmd templateMsg )
|
, init : templateMetadata -> ( templateModel, Cmd templateMsg )
|
||||||
, update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg )
|
, update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg )
|
||||||
|
, subscriptions : templateMetadata -> PagePath Pages.PathKey -> DynamicPayload templateModel -> Sub templateMsg
|
||||||
}
|
}
|
||||||
-> Template templateMetadata templateStaticData templateModel templateMsg
|
-> Template templateMetadata templateStaticData templateModel templateMsg
|
||||||
application config =
|
application config =
|
||||||
@ -107,6 +115,7 @@ application config =
|
|||||||
, staticData = config.staticData
|
, staticData = config.staticData
|
||||||
, init = config.init
|
, init = config.init
|
||||||
, update = config.update
|
, update = config.update
|
||||||
|
, subscriptions = config.subscriptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -125,6 +134,7 @@ type alias Template templateMetadata templateStaticData templateModel templateMs
|
|||||||
-> List (Head.Tag Pages.PathKey)
|
-> List (Head.Tag Pages.PathKey)
|
||||||
, init : templateMetadata -> ( templateModel, Cmd templateMsg )
|
, init : templateMetadata -> ( templateModel, Cmd templateMsg )
|
||||||
, update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg )
|
, update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg )
|
||||||
|
, subscriptions : templateMetadata -> PagePath Pages.PathKey -> DynamicPayload templateModel -> Sub templateMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ template =
|
|||||||
, staticData = staticData
|
, staticData = staticData
|
||||||
, init = init
|
, init = init
|
||||||
, update = update
|
, update = update
|
||||||
|
, subscriptions = \_ _ _ -> Sub.none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,9 +78,7 @@ imageDecoder =
|
|||||||
|
|
||||||
findMatchingImage : String -> Maybe (ImagePath Pages.PathKey)
|
findMatchingImage : String -> Maybe (ImagePath Pages.PathKey)
|
||||||
findMatchingImage imageAssetPath =
|
findMatchingImage imageAssetPath =
|
||||||
List.Extra.find
|
List.Extra.find (\image -> ImagePath.toString image == imageAssetPath) Pages.allImages
|
||||||
(\image -> ImagePath.toString image == imageAssetPath)
|
|
||||||
Pages.allImages
|
|
||||||
|
|
||||||
|
|
||||||
view :
|
view :
|
||||||
|
@ -40,6 +40,7 @@ template =
|
|||||||
, staticData = staticData
|
, staticData = staticData
|
||||||
, init = init
|
, init = init
|
||||||
, update = update
|
, update = update
|
||||||
|
, subscriptions = \_ _ _ -> Sub.none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -206,13 +206,42 @@ type alias SiteConfig =
|
|||||||
, manifest : Manifest.Config Pages.PathKey
|
, manifest : Manifest.Config Pages.PathKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templateSubscriptions : Metadata -> PagePath Pages.PathKey -> Model -> Sub Msg
|
||||||
|
templateSubscriptions metadata path model =
|
||||||
|
case model.page of
|
||||||
|
${templates.map(name => `
|
||||||
|
Model${name} templateModel ->
|
||||||
|
case metadata of
|
||||||
|
M.Metadata${name} templateMetadata ->
|
||||||
|
Template.${name}.template.subscriptions
|
||||||
|
templateMetadata
|
||||||
|
path
|
||||||
|
{ model = templateModel
|
||||||
|
, sharedModel = model.global
|
||||||
|
}
|
||||||
|
|> Sub.map Msg${name}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Sub.none
|
||||||
|
`
|
||||||
|
).join("\n ")}
|
||||||
|
|
||||||
|
|
||||||
|
NotFound ->
|
||||||
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
mainTemplate { documents, subscriptions, site } =
|
mainTemplate { documents, subscriptions, site } =
|
||||||
Pages.Platform.init
|
Pages.Platform.init
|
||||||
{ init = init Nothing
|
{ init = init Nothing
|
||||||
, view = view
|
, view = view
|
||||||
, update = update
|
, update = update
|
||||||
, subscriptions = subscriptions
|
, subscriptions =
|
||||||
|
\\metadata path model ->
|
||||||
|
Sub.batch
|
||||||
|
[ subscriptions
|
||||||
|
, templateSubscriptions metadata path model
|
||||||
|
]
|
||||||
, documents = documents
|
, documents = documents
|
||||||
, onPageChange = Just OnPageChange
|
, onPageChange = Just OnPageChange
|
||||||
, manifest = site.manifest
|
, manifest = site.manifest
|
||||||
|
@ -727,7 +727,7 @@ application :
|
|||||||
}
|
}
|
||||||
-> ( userModel, Cmd userMsg )
|
-> ( userModel, Cmd userMsg )
|
||||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||||
, subscriptions : userModel -> Sub userMsg
|
, subscriptions : metadata -> PagePath pathKey -> userModel -> Sub userMsg
|
||||||
, view :
|
, view :
|
||||||
List ( PagePath pathKey, metadata )
|
List ( PagePath pathKey, metadata )
|
||||||
->
|
->
|
||||||
@ -822,10 +822,33 @@ application config =
|
|||||||
\outerModel ->
|
\outerModel ->
|
||||||
case outerModel of
|
case outerModel of
|
||||||
Model model ->
|
Model model ->
|
||||||
|
let
|
||||||
|
urls =
|
||||||
|
{ currentUrl = model.url
|
||||||
|
, baseUrl = model.baseUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
( maybePagePath, maybeMetadata ) =
|
||||||
|
case ContentCache.lookupMetadata config.pathKey model.contentCache urls of
|
||||||
|
Just ( pagePath, metadata ) ->
|
||||||
|
( Just pagePath, Just metadata )
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
( Nothing, Nothing )
|
||||||
|
|
||||||
|
userSub =
|
||||||
|
Maybe.map2
|
||||||
|
(\metadata path ->
|
||||||
|
config.subscriptions metadata path model.userModel
|
||||||
|
|> Sub.map UserMsg
|
||||||
|
|> Sub.map AppMsg
|
||||||
|
)
|
||||||
|
maybeMetadata
|
||||||
|
maybePagePath
|
||||||
|
|> Maybe.withDefault Sub.none
|
||||||
|
in
|
||||||
Sub.batch
|
Sub.batch
|
||||||
[ config.subscriptions model.userModel
|
[ userSub
|
||||||
|> Sub.map UserMsg
|
|
||||||
|> Sub.map AppMsg
|
|
||||||
, config.fromJsPort
|
, config.fromJsPort
|
||||||
|> Sub.map
|
|> Sub.map
|
||||||
(\decodeValue ->
|
(\decodeValue ->
|
||||||
@ -863,7 +886,7 @@ cliApplication :
|
|||||||
}
|
}
|
||||||
-> ( userModel, Cmd userMsg )
|
-> ( userModel, Cmd userMsg )
|
||||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||||
, subscriptions : userModel -> Sub userMsg
|
, subscriptions : metadata -> PagePath pathKey -> userModel -> Sub userMsg
|
||||||
, view :
|
, view :
|
||||||
List ( PagePath pathKey, metadata )
|
List ( PagePath pathKey, metadata )
|
||||||
->
|
->
|
||||||
|
@ -79,7 +79,7 @@ type alias Config pathKey userMsg userModel metadata view =
|
|||||||
}
|
}
|
||||||
-> ( userModel, Cmd userMsg )
|
-> ( userModel, Cmd userMsg )
|
||||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||||
, subscriptions : userModel -> Sub userMsg
|
, subscriptions : metadata -> PagePath pathKey -> userModel -> Sub userMsg
|
||||||
, view :
|
, view :
|
||||||
List ( PagePath pathKey, metadata )
|
List ( PagePath pathKey, metadata )
|
||||||
->
|
->
|
||||||
|
@ -92,7 +92,7 @@ type Builder pathKey model msg metadata view
|
|||||||
}
|
}
|
||||||
-> ( model, Cmd msg )
|
-> ( model, Cmd msg )
|
||||||
, update : msg -> model -> ( model, Cmd msg )
|
, update : msg -> model -> ( model, Cmd msg )
|
||||||
, subscriptions : model -> Sub msg
|
, subscriptions : metadata -> PagePath pathKey -> model -> Sub msg
|
||||||
, view :
|
, view :
|
||||||
List ( PagePath pathKey, metadata )
|
List ( PagePath pathKey, metadata )
|
||||||
->
|
->
|
||||||
@ -185,7 +185,7 @@ init :
|
|||||||
{ view : model -> view -> { title : String, body : Html msg }
|
{ view : model -> view -> { title : String, body : Html msg }
|
||||||
, head : List (Head.Tag pathKey)
|
, head : List (Head.Tag pathKey)
|
||||||
}
|
}
|
||||||
, subscriptions : model -> Sub msg
|
, subscriptions : metadata -> PagePath pathKey -> model -> Sub msg
|
||||||
, documents :
|
, documents :
|
||||||
List
|
List
|
||||||
{ extension : String
|
{ extension : String
|
||||||
@ -330,7 +330,7 @@ application :
|
|||||||
}
|
}
|
||||||
-> ( model, Cmd msg )
|
-> ( model, Cmd msg )
|
||||||
, update : msg -> model -> ( model, Cmd msg )
|
, update : msg -> model -> ( model, Cmd msg )
|
||||||
, subscriptions : model -> Sub msg
|
, subscriptions : metadata -> PagePath pathKey -> model -> Sub msg
|
||||||
, view :
|
, view :
|
||||||
List ( PagePath pathKey, metadata )
|
List ( PagePath pathKey, metadata )
|
||||||
->
|
->
|
||||||
|
Loading…
Reference in New Issue
Block a user