Skip to content

Commit

Permalink
refactor app code for simpler build
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Feb 1, 2025
1 parent a983033 commit 3c35df0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
51 changes: 31 additions & 20 deletions implement/example-apps/elm-editor/src/Backend/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ updatePartRequestsToVolatileProcess stateBefore =
[ Platform.WebService.CreateVolatileProcess
{ programCode = VolatileProcess.volatileProcessProgramCode
, update =
\createVolatileProcessResult ->
processEvent (CreateVolatileProcessResponse createVolatileProcessResult)
\createVolatileProcessResult state ->
processEvent
(CreateVolatileProcessResponse createVolatileProcessResult)
state
}
]

Expand Down Expand Up @@ -148,9 +150,10 @@ updatePartRequestsToVolatileProcess stateBefore =
|> Maybe.andThen Common.decodeBase64ToString
|> Maybe.withDefault "Error decoding base64"
, update =
\requestToVolatileProcessResponse ->
\requestToVolatileProcessResponse state ->
processEvent
(RequestToVolatileProcessResponse taskId requestToVolatileProcessResponse)
state
}

pendingTasksForRequestVolatileProcess =
Expand Down Expand Up @@ -233,11 +236,16 @@ updateForHttpRequestEventExceptRequestsToVolatileProcess httpRequestEvent stateB
]
)
in
case httpRequestEvent.request.uri |> Url.fromString of
case Url.fromString httpRequestEvent.request.uri of
Nothing ->
continueWithStaticHttpResponse
{ statusCode = 500
, bodyAsBase64 = bodyFromString "Failed to parse URL"
, bodyAsBase64 =
bodyFromString
("Failed to parse URL ("
++ httpRequestEvent.request.uri
++ ")"
)
, headersToAdd = []
}

Expand Down Expand Up @@ -277,19 +285,14 @@ updateForHttpRequestEventExceptRequestsToVolatileProcess httpRequestEvent stateB
Just (Backend.Route.StaticFileRoute (Backend.Route.FrontendElmJavascriptRoute { debug })) ->
httpResponseOkWithBodyAsBase64
(Just
(if debug then
CompilationInterface.ElmMake.elm_make____src_Frontend_Main_elm.debug.javascript.base64

else
CompilationInterface.ElmMake.elm_make____src_Frontend_Main_elm.javascript.base64
)
CompilationInterface.ElmMake.elm_make____src_Frontend_Main_elm.javascript.base64
)
(staticContentHttpHeaders { contentType = "text/javascript", contentEncoding = Nothing })
|> continueWithStaticHttpResponse

Just (Backend.Route.StaticFileRoute Backend.Route.FrontendLanguageServiceWorkerJavaScriptRoute) ->
httpResponseOkWithBodyAsBase64
(Just languageServiceWorkerJavaScriptBase64)
(Just (languageServiceWorkerJavaScriptBase64 ()))
(staticContentHttpHeaders { contentType = "text/javascript", contentEncoding = Nothing })
|> continueWithStaticHttpResponse

Expand All @@ -301,10 +304,14 @@ updateForHttpRequestEventExceptRequestsToVolatileProcess httpRequestEvent stateB
)


languageServiceWorkerJavaScript : String
languageServiceWorkerJavaScript =
CompilationInterface.ElmMake.elm_make____src_LanguageServiceWorker_elm.javascript.utf8
++ """
languageServiceWorkerJavaScript : () -> String
languageServiceWorkerJavaScript () =
case Base64.toString CompilationInterface.ElmMake.elm_make____src_LanguageServiceWorker_elm.javascript.base64 of
Nothing ->
"Failed decoding base64"

Just workerJavaScript ->
workerJavaScript ++ """
const app = Elm.LanguageServiceWorker.init();
onmessage = function ({ data }) {
Expand All @@ -319,10 +326,14 @@ app.ports.sendResponse.subscribe(function(response) {
"""


languageServiceWorkerJavaScriptBase64 : String
languageServiceWorkerJavaScriptBase64 =
Maybe.withDefault "Failed encoding as base64"
(Base64.fromString languageServiceWorkerJavaScript)
languageServiceWorkerJavaScriptBase64 : () -> String
languageServiceWorkerJavaScriptBase64 () =
case Base64.fromString (languageServiceWorkerJavaScript ()) of
Nothing ->
"Failed encoding as base64"

Just base64 ->
base64


updateForRequestToVolatileProcessResult :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
module CompilationInterface.ElmMake exposing (..)


elm_make____src_Frontend_Main_elm : { debug : { javascript : { base64 : String } }, javascript : { base64 : String } }
elm_make____src_Frontend_Main_elm : { javascript : { base64 : String } }
elm_make____src_Frontend_Main_elm =
{ javascript = { base64 = "The compiler replaces this declaration." }
, debug = { javascript = { base64 = "The compiler replaces this declaration." } }
}


elm_make____src_LanguageServiceWorker_elm : { javascript : { utf8 : String } }
elm_make____src_LanguageServiceWorker_elm : { javascript : { base64 : String } }
elm_make____src_LanguageServiceWorker_elm =
{ javascript = { utf8 = "The compiler replaces this declaration." }
{ javascript = { base64 = "The compiler replaces this declaration." }
}

0 comments on commit 3c35df0

Please sign in to comment.