Simplify gotBatchPort payload (bytes are being handled as base64 string so may as well remove the Bytes part now since it's unused - might change it back for performance if it makes a difference).

This commit is contained in:
Dillon Kearns 2022-02-25 11:50:24 -08:00
parent 9ced0ccd2b
commit 1c56e82258
5 changed files with 18 additions and 30 deletions

View File

@ -793,7 +793,7 @@ port toJsPort : Json.Encode.Value -> Cmd msg
port fromJsPort : (Json.Decode.Value -> msg) -> Sub msg
port gotBatchSub : (List { requestAndResponse : Json.Decode.Value, maybeBytes : Maybe Bytes } -> msg) -> Sub msg
port gotBatchSub : (List Json.Decode.Value -> msg) -> Sub msg
mapBoth : (a -> b) -> (c -> d) -> ( a, c, e ) -> ( b, d, e )

View File

@ -288,13 +288,10 @@ async function runHttpJob(app, mode, requestToPerform, fs, hasFsAccess) {
);
pendingDataSourceResponses.push({
requestAndResponse: {
request: requestToPerform,
response: JSON.parse(
(await fs.promises.readFile(responseFilePath, "utf8")).toString()
),
},
maybeBytes: null,
request: requestToPerform,
response: JSON.parse(
(await fs.promises.readFile(responseFilePath, "utf8")).toString()
),
});
} catch (error) {
sendError(app, error);
@ -306,17 +303,14 @@ async function runHttpJob(app, mode, requestToPerform, fs, hasFsAccess) {
function stringResponse(request, string) {
return {
requestAndResponse: {
request,
response: { bodyKind: "string", body: string },
},
maybeBytes: null,
request,
response: { bodyKind: "string", body: string },
};
}
function jsonResponse(request, json) {
return {
requestAndResponse: { request, response: { bodyKind: "json", body: json } },
maybeBytes: null,
request,
response: { bodyKind: "json", body: json },
};
}

View File

@ -163,11 +163,11 @@ cliApplication config =
, response = response
}
)
(item.requestAndResponse
(item
|> Decode.decodeValue (Decode.field "request" requestDecoder)
)
(item.requestAndResponse
|> Decode.decodeValue (Decode.field "response" (RequestsAndPending.decoder item.maybeBytes))
(item
|> Decode.decodeValue (Decode.field "response" RequestsAndPending.decoder)
)
of
Ok okValue ->

View File

@ -63,13 +63,7 @@ type alias ProgramConfig userMsg userModel route pageData sharedData =
, site : Maybe SiteConfig
, toJsPort : Json.Encode.Value -> Cmd Never
, fromJsPort : Sub Decode.Value
, gotBatchSub :
Sub
(List
{ requestAndResponse : Decode.Value
, maybeBytes : Maybe Bytes
}
)
, gotBatchSub : Sub (List Decode.Value)
, hotReloadData : Sub Bytes
, onPageChange :
{ protocol : Url.Protocol

View File

@ -17,15 +17,15 @@ type ResponseBody
| WhateverBody
decoder : Maybe Bytes -> Decoder Response
decoder maybeBytes =
decoder : Decoder Response
decoder =
Decode.map2 Response
(Decode.maybe responseDecoder)
(decoder_ maybeBytes)
bodyDecoder
decoder_ : Maybe Bytes -> Decoder ResponseBody
decoder_ maybeBytesBody =
bodyDecoder : Decoder ResponseBody
bodyDecoder =
Decode.field "bodyKind" Decode.string
|> Decode.andThen
(\bodyKind ->