Extract helper.

This commit is contained in:
Dillon Kearns 2022-09-16 13:11:23 -07:00
parent 652215fdf9
commit 3301d3110c

View File

@ -368,17 +368,8 @@ otherFile routes phaseString =
, just =
( "route"
, \justRoute ->
Elm.Case.custom justRoute
Type.unit
(routes
|> List.map
(\route ->
let
moduleName =
"Route." ++ (RoutePattern.toModuleName route |> String.join "__")
expression : Elm.Expression -> Elm.Expression
expression innerRecord =
branchHelper justRoute
(\route innerRecord ->
Elm.apply
(Elm.value
{ annotation = Nothing
@ -399,22 +390,11 @@ otherFile routes phaseString =
]
, Elm.fn ( "param", Nothing )
(\param ->
Elm.list []
-- TODO not implemented
todo
)
, innerRecord
, innerRecord |> Maybe.withDefault (Elm.record [])
]
in
if RoutePattern.hasRouteParams route then
Elm.Case.branch1 moduleName
( "routeParams", Type.unit )
(\routeParams ->
expression routeParams
)
else
Elm.Case.branch0 moduleName
(expression (Elm.record []))
)
)
)
}
@ -422,6 +402,31 @@ otherFile routes phaseString =
(Gen.DataSource.annotation_.dataSource (Type.maybe Gen.Pages.Internal.NotFoundReason.annotation_.notFoundReason))
)
branchHelper : Elm.Expression -> (RoutePattern -> Maybe Elm.Expression -> Elm.Expression) -> Elm.Expression
branchHelper routeExpression toInnerExpression =
Elm.Case.custom routeExpression
Type.unit
(routes
|> List.map
(\route ->
let
moduleName : String
moduleName =
"Route." ++ (RoutePattern.toModuleName route |> String.join "__")
in
if RoutePattern.hasRouteParams route then
Elm.Case.branch1 moduleName
( "routeParams", Type.unit )
(\routeParams ->
toInnerExpression route (Just routeParams)
)
else
Elm.Case.branch0 moduleName
(toInnerExpression route Nothing)
)
)
encodeActionData :
{ declaration : Elm.Declaration
, call : Elm.Expression -> Elm.Expression