mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-24 12:22:27 +03:00
Generate encode/decode response.
This commit is contained in:
parent
a34bb131b5
commit
7b14ac59d9
@ -11,6 +11,8 @@ import Elm.Pretty
|
||||
import Gen.ApiRoute
|
||||
import Gen.Basics
|
||||
import Gen.Bytes
|
||||
import Gen.Bytes.Decode
|
||||
import Gen.Bytes.Encode
|
||||
import Gen.CodeGen.Generate exposing (Error)
|
||||
import Gen.DataSource
|
||||
import Gen.Head
|
||||
@ -121,9 +123,9 @@ otherFile routes phaseString =
|
||||
, sendPageData = Elm.val "sendPageData"
|
||||
, byteEncodePageData = todo
|
||||
, byteDecodePageData = todo
|
||||
, encodeResponse = todo
|
||||
, encodeResponse = encodeResponse.reference
|
||||
, encodeAction = todo
|
||||
, decodeResponse = todo
|
||||
, decodeResponse = decodeResponse.reference
|
||||
, globalHeadTags =
|
||||
case phase of
|
||||
Browser ->
|
||||
@ -214,6 +216,78 @@ otherFile routes phaseString =
|
||||
)
|
||||
)
|
||||
|
||||
encodeResponse :
|
||||
{ declaration : Elm.Declaration
|
||||
, reference : Elm.Expression
|
||||
, referenceFrom : List String -> Elm.Expression
|
||||
}
|
||||
encodeResponse =
|
||||
topLevelValue "encodeResponse"
|
||||
(Elm.apply
|
||||
(Elm.value
|
||||
{ annotation = Nothing
|
||||
, name = "w3_encode_ResponseSketch"
|
||||
, importFrom =
|
||||
[ "Pages", "Internal", "ResponseSketch" ]
|
||||
}
|
||||
)
|
||||
[ Elm.val "w3_encode_PageData"
|
||||
, Elm.val "w3_encode_ActionData"
|
||||
, Elm.value
|
||||
{ annotation = Nothing
|
||||
, name = "w3_encode_Data"
|
||||
, importFrom =
|
||||
[ "Shared" ]
|
||||
}
|
||||
]
|
||||
|> Elm.withType
|
||||
(Type.function
|
||||
[ Type.namedWith [ "Pages", "Internal", "ResponseSketch" ]
|
||||
"ResponseSketch"
|
||||
[ Type.named [] "PageData"
|
||||
, Type.named [] "ActionData"
|
||||
, Type.named [ "Shared" ] "Data"
|
||||
]
|
||||
]
|
||||
Gen.Bytes.Encode.annotation_.encoder
|
||||
)
|
||||
)
|
||||
|
||||
decodeResponse :
|
||||
{ declaration : Elm.Declaration
|
||||
, reference : Elm.Expression
|
||||
, referenceFrom : List String -> Elm.Expression
|
||||
}
|
||||
decodeResponse =
|
||||
topLevelValue "decodeResponse"
|
||||
(Elm.apply
|
||||
(Elm.value
|
||||
{ annotation = Nothing
|
||||
, name = "w3_decode_ResponseSketch"
|
||||
, importFrom =
|
||||
[ "Pages", "Internal", "ResponseSketch" ]
|
||||
}
|
||||
)
|
||||
[ Elm.val "w3_decode_PageData"
|
||||
, Elm.val "w3_decode_ActionData"
|
||||
, Elm.value
|
||||
{ annotation = Nothing
|
||||
, name = "w3_decode_Data"
|
||||
, importFrom =
|
||||
[ "Shared" ]
|
||||
}
|
||||
]
|
||||
|> Elm.withType
|
||||
(Type.namedWith [ "Pages", "Internal", "ResponseSketch" ]
|
||||
"ResponseSketch"
|
||||
[ Type.named [] "PageData"
|
||||
, Type.named [] "ActionData"
|
||||
, Type.named [ "Shared" ] "Data"
|
||||
]
|
||||
|> Gen.Bytes.Decode.annotation_.decoder
|
||||
)
|
||||
)
|
||||
|
||||
getStaticRoutes :
|
||||
{ declaration : Elm.Declaration
|
||||
, reference : Elm.Expression
|
||||
@ -379,6 +453,8 @@ otherFile routes phaseString =
|
||||
]
|
||||
)
|
||||
, globalHeadTags.declaration
|
||||
, encodeResponse.declaration
|
||||
, decodeResponse.declaration
|
||||
, Elm.portIncoming "hotReloadData"
|
||||
[ Gen.Bytes.annotation_.bytes ]
|
||||
, Elm.portOutgoing "toJsPort"
|
||||
|
Loading…
Reference in New Issue
Block a user