mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-29 14:56:36 +03:00
Simplify handleRoute and remove Maybe wrapper.
This commit is contained in:
parent
eb4f375f16
commit
dff859ce08
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user