Wire through (Maybe (PagePath pathKey)) as init argument.

This commit is contained in:
Dillon Kearns 2019-10-08 21:12:17 -07:00
parent fcc3661909
commit 431b350858
4 changed files with 32 additions and 19 deletions

View File

@ -432,22 +432,23 @@ lookup pathKey content url =
lookupMetadata : lookupMetadata :
ContentCache metadata view pathKey
-> ContentCache metadata view
-> Url -> Url
-> Maybe metadata -> Maybe ( PagePath pathKey, metadata )
lookupMetadata content url = lookupMetadata pathKey content url =
lookup () content url lookup pathKey content url
|> Maybe.map |> Maybe.map
(\( pagePath, entry ) -> (\( pagePath, entry ) ->
case entry of case entry of
NeedContent _ metadata -> NeedContent _ metadata ->
metadata ( pagePath, metadata )
Unparsed _ metadata _ -> Unparsed _ metadata _ ->
metadata ( pagePath, metadata )
Parsed metadata _ -> Parsed metadata _ ->
metadata ( pagePath, metadata )
) )

View File

@ -177,28 +177,37 @@ init :
-> (Json.Encode.Value -> Cmd (Msg userMsg metadata view)) -> (Json.Encode.Value -> Cmd (Msg userMsg metadata view))
-> (metadata -> List (Head.Tag pathKey)) -> (metadata -> List (Head.Tag pathKey))
-> Content -> Content
-> ( userModel, Cmd userMsg ) -> (Maybe (PagePath pathKey) -> ( userModel, Cmd userMsg ))
-> Flags -> Flags
-> Url -> Url
-> Browser.Navigation.Key -> Browser.Navigation.Key
-> ( ModelDetails userModel metadata view, Cmd (Msg userMsg metadata view) ) -> ( ModelDetails userModel metadata view, Cmd (Msg userMsg metadata view) )
init pathKey canonicalSiteUrl document toJsPort head content initUserModel flags url key = init pathKey canonicalSiteUrl document toJsPort head content initUserModel flags url key =
let let
( userModel, userCmd ) =
initUserModel
contentCache = contentCache =
ContentCache.init document content ContentCache.init document content
in in
case contentCache of case contentCache of
Ok okCache -> Ok okCache ->
let
( userModel, userCmd ) =
initUserModel maybePagePath
( maybePagePath, maybeMetadata ) =
case ContentCache.lookupMetadata pathKey (Ok okCache) url of
Just ( pagePath, metadata ) ->
( Just pagePath, Just metadata )
Nothing ->
( Nothing, Nothing )
in
( { key = key ( { key = key
, url = url , url = url
, userModel = userModel , userModel = userModel
, contentCache = contentCache , contentCache = contentCache
} }
, Cmd.batch , Cmd.batch
([ ContentCache.lookupMetadata (Ok okCache) url ([ maybeMetadata
|> Maybe.map head |> Maybe.map head
|> Maybe.map (encodeHeads canonicalSiteUrl url.path) |> Maybe.map (encodeHeads canonicalSiteUrl url.path)
|> Maybe.map toJsPort |> Maybe.map toJsPort
@ -213,6 +222,10 @@ init pathKey canonicalSiteUrl document toJsPort head content initUserModel flags
) )
Err _ -> Err _ ->
let
( userModel, userCmd ) =
initUserModel Nothing
in
( { key = key ( { key = key
, url = url , url = url
, userModel = userModel , userModel = userModel
@ -332,7 +345,7 @@ type alias Parser metadata view =
application : application :
{ init : ( userModel, Cmd userMsg ) { init : Maybe (PagePath pathKey) -> ( userModel, Cmd userMsg )
, update : userMsg -> userModel -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : userModel -> Sub userMsg , subscriptions : userModel -> Sub userMsg
, view : userModel -> List ( PagePath pathKey, metadata ) -> Page metadata view pathKey -> { title : String, body : Html userMsg } , view : userModel -> List ( PagePath pathKey, metadata ) -> Page metadata view pathKey -> { title : String, body : Html userMsg }
@ -385,7 +398,7 @@ application config =
cliApplication : cliApplication :
{ init : ( userModel, Cmd userMsg ) { init : Maybe (PagePath pathKey) -> ( userModel, Cmd userMsg )
, update : userMsg -> userModel -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : userModel -> Sub userMsg , subscriptions : userModel -> Sub userMsg
, view : userModel -> List ( PagePath pathKey, metadata ) -> Page metadata view pathKey -> { title : String, body : Html userMsg } , view : userModel -> List ( PagePath pathKey, metadata ) -> Page metadata view pathKey -> { title : String, body : Html userMsg }
@ -444,4 +457,3 @@ encodeErrors errors =
|> Json.Encode.dict |> Json.Encode.dict
(\path -> "/" ++ String.join "/" path) (\path -> "/" ++ String.join "/" path)
(\errorsForPath -> Json.Encode.string errorsForPath) (\errorsForPath -> Json.Encode.string errorsForPath)

View File

@ -78,8 +78,8 @@ type alias Model =
{} {}
init : ( Model, Cmd Msg ) init : Maybe (PagePath Pages.PathKey) -> ( Model, Cmd Msg )
init = init maybePagePath =
( Model, Cmd.none ) ( Model, Cmd.none )

View File

@ -89,7 +89,7 @@ port toJsPort : Json.Encode.Value -> Cmd msg
application : application :
{ init : ( userModel, Cmd userMsg ) { init : Maybe (PagePath PathKey) -> ( userModel, Cmd userMsg )
, update : userMsg -> userModel -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : userModel -> Sub userMsg , subscriptions : userModel -> Sub userMsg
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg } , view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }
@ -169,7 +169,7 @@ port toJsPort : Json.Encode.Value -> Cmd msg
application : application :
{ init : ( userModel, Cmd userMsg ) { init : Maybe (PagePath PathKey) -> ( userModel, Cmd userMsg )
, update : userMsg -> userModel -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : userModel -> Sub userMsg , subscriptions : userModel -> Sub userMsg
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg } , view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }