Migrate more code.

This commit is contained in:
Dillon Kearns 2022-09-16 09:11:06 -07:00
parent 6e5470cd54
commit dc92df986f

View File

@ -158,7 +158,7 @@ otherFile routes phaseString =
, byteEncodePageData = todo
, byteDecodePageData = todo
, encodeResponse = encodeResponse.reference
, encodeAction = todo
, encodeAction = Elm.val "encodeActionData"
, decodeResponse = decodeResponse.reference
, globalHeadTags =
case phase of
@ -302,6 +302,38 @@ otherFile routes phaseString =
(Gen.DataSource.annotation_.dataSource (Type.maybe Gen.Pages.Internal.NotFoundReason.annotation_.notFoundReason))
)
encodeActionData :
{ declaration : Elm.Declaration
, call : Elm.Expression -> Elm.Expression
, callFrom : List String -> Elm.Expression -> Elm.Expression
}
encodeActionData =
Elm.Declare.fn "encodeActionData"
( "actionData", Type.named [] "ActionData" |> Just )
(\actionData ->
Elm.Case.custom actionData
Type.unit
(routes
|> List.map
(\route ->
Elm.Case.branch1
("ActionData" ++ (RoutePattern.toModuleName route |> String.join "__"))
( "thisActionData", Type.unit )
(\thisActionData ->
Elm.apply
(Elm.value
{ annotation = Nothing
, importFrom = "Route" :: RoutePattern.toModuleName route
, name = "w3_encode_ActionData"
}
)
[ thisActionData ]
)
)
)
|> Elm.withType Gen.Bytes.Encode.annotation_.encoder
)
pathsToGenerateHandler :
{ declaration : Elm.Declaration
, reference : Elm.Expression
@ -737,6 +769,7 @@ otherFile routes phaseString =
, pathsToGenerateHandler.declaration
, getStaticRoutes.declaration
, handleRoute.declaration
, encodeActionData.declaration
, Elm.portOutgoing "sendPageData"
(Type.record
[ ( "oldThing", Gen.Json.Encode.annotation_.value )