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