Simplify handleRoute and remove Maybe wrapper.

This commit is contained in:
Dillon Kearns 2021-04-26 10:11:16 -07:00
parent eb4f375f16
commit dff859ce08
2 changed files with 8 additions and 23 deletions

View File

@ -68,7 +68,7 @@ type alias PageWithState routeParams templateData templateModel templateMsg =
, init : StaticPayload templateData routeParams -> ( templateModel, Cmd templateMsg )
, update : StaticPayload templateData routeParams -> Maybe Browser.Navigation.Key -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : routeParams -> PagePath -> templateModel -> Shared.Model -> Sub templateMsg
, handleRoute : Maybe (routeParams -> DataSource Bool)
, handleRoute : routeParams -> DataSource Bool
}
@ -95,7 +95,7 @@ type Builder routeParams templateData
StaticPayload templateData routeParams
-> List Head.Tag
, serverless : Bool
, handleRoute : Maybe (routeParams -> DataSource Bool)
, handleRoute : routeParams -> DataSource Bool
}
@ -218,7 +218,7 @@ singleRoute { data, head } =
, staticRoutes = DataSource.succeed [ {} ]
, head = head
, serverless = False
, handleRoute = Nothing
, handleRoute = \_ -> DataSource.succeed True
}
@ -235,7 +235,7 @@ prerenderedRoute { data, head, routes } =
, staticRoutes = routes
, head = head
, serverless = False
, handleRoute = Nothing
, handleRoute = \routeParams -> routes |> DataSource.map (List.member routeParams)
}
@ -252,7 +252,7 @@ serverlessRoute { data, head, routeFound } =
, staticRoutes = DataSource.succeed []
, head = head
, serverless = True
, handleRoute = Just routeFound
, handleRoute = routeFound
}

View File

@ -440,7 +440,9 @@ handleRoute maybeRoute =
(name) =>
`Just (Route.${routeHelpers.routeVariant(
name
)} routeParams) ->\n ${handleRoute(name)}`
)} routeParams) ->\n Page.${name.join(
"."
)}.page.handleRoute routeParams`
)
.join("\n ")}
@ -618,21 +620,4 @@ function moduleName(name) {
return name.join(".");
}
/**
*
* @param {string[]} name
*/
function handleRoute(name) {
if (routeHelpers.routeParams(name).length > 0) {
return `Page.${name.join(
"."
)}.page.staticRoutes |> DataSource.map (List.member routeParams)`;
} else {
return `Page.${name.join(".")}.page.handleRoute
|> Maybe.map (\\handler -> handler routeParams)
|> Maybe.withDefault (DataSource.succeed True)
`;
}
}
module.exports = { generateTemplateModuleConnector };