mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-24 12:22:27 +03:00
Extract helper.
This commit is contained in:
parent
652215fdf9
commit
3301d3110c
@ -368,53 +368,33 @@ 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 =
|
||||
Elm.apply
|
||||
(Elm.value
|
||||
{ annotation = Nothing
|
||||
, importFrom = "Route" :: RoutePattern.toModuleName route
|
||||
, name = "route"
|
||||
}
|
||||
|> Elm.get "handleRoute"
|
||||
)
|
||||
[ Elm.record
|
||||
[ ( "moduleName"
|
||||
, RoutePattern.toModuleName route
|
||||
|> List.map Elm.string
|
||||
|> Elm.list
|
||||
)
|
||||
, ( "routePattern"
|
||||
, routePatternToSyntax route
|
||||
)
|
||||
]
|
||||
, Elm.fn ( "param", Nothing )
|
||||
(\param ->
|
||||
Elm.list []
|
||||
)
|
||||
, innerRecord
|
||||
]
|
||||
in
|
||||
if RoutePattern.hasRouteParams route then
|
||||
Elm.Case.branch1 moduleName
|
||||
( "routeParams", Type.unit )
|
||||
(\routeParams ->
|
||||
expression routeParams
|
||||
)
|
||||
|
||||
else
|
||||
Elm.Case.branch0 moduleName
|
||||
(expression (Elm.record []))
|
||||
branchHelper justRoute
|
||||
(\route innerRecord ->
|
||||
Elm.apply
|
||||
(Elm.value
|
||||
{ annotation = Nothing
|
||||
, importFrom = "Route" :: RoutePattern.toModuleName route
|
||||
, name = "route"
|
||||
}
|
||||
|> Elm.get "handleRoute"
|
||||
)
|
||||
[ Elm.record
|
||||
[ ( "moduleName"
|
||||
, RoutePattern.toModuleName route
|
||||
|> List.map Elm.string
|
||||
|> Elm.list
|
||||
)
|
||||
, ( "routePattern"
|
||||
, routePatternToSyntax route
|
||||
)
|
||||
]
|
||||
, Elm.fn ( "param", Nothing )
|
||||
(\param ->
|
||||
-- TODO not implemented
|
||||
todo
|
||||
)
|
||||
, innerRecord |> Maybe.withDefault (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
|
||||
|
Loading…
Reference in New Issue
Block a user