mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 23:06:10 +03:00
Remove some levels of indirection.
This commit is contained in:
parent
7d409f611a
commit
b21a954b90
@ -23,7 +23,7 @@ import Pages.Flags
|
||||
import Pages.Internal.NotFoundReason as NotFoundReason exposing (NotFoundReason)
|
||||
import Pages.Internal.Platform.CompatibilityKey
|
||||
import Pages.Internal.Platform.Effect as Effect exposing (Effect)
|
||||
import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses)
|
||||
import Pages.Internal.Platform.StaticResponses as StaticResponses
|
||||
import Pages.Internal.Platform.ToJsPayload as ToJsPayload
|
||||
import Pages.Internal.ResponseSketch as ResponseSketch
|
||||
import Pages.Msg
|
||||
@ -50,7 +50,7 @@ currentCompatibilityKey =
|
||||
|
||||
{-| -}
|
||||
type alias Model route =
|
||||
{ staticResponses : StaticResponses Effect
|
||||
{ staticResponses : DataSource Effect
|
||||
, errors : List BuildError
|
||||
, allRawResponses : RequestsAndPending
|
||||
, maybeRequestJson : RenderRequest route
|
||||
@ -425,7 +425,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
|
||||
globalHeadTags =
|
||||
(config.globalHeadTags |> Maybe.withDefault (\_ -> DataSource.succeed [])) HtmlPrinter.htmlToString
|
||||
|
||||
staticResponsesNew : StaticResponses Effect
|
||||
staticResponsesNew : DataSource Effect
|
||||
staticResponsesNew =
|
||||
StaticResponses.renderApiRequest
|
||||
(case singleRequest of
|
||||
@ -862,11 +862,11 @@ nextStepToEffect :
|
||||
SiteConfig
|
||||
-> ProgramConfig userMsg userModel route pageData actionData sharedData effect mappedMsg errorPage
|
||||
-> Model route
|
||||
-> ( StaticResponses Effect, StaticResponses.NextStep route Effect )
|
||||
-> StaticResponses.NextStep route Effect
|
||||
-> ( Model route, Effect )
|
||||
nextStepToEffect site config model ( updatedStaticResponsesModel, nextStep ) =
|
||||
nextStepToEffect site config model nextStep =
|
||||
case nextStep of
|
||||
StaticResponses.Continue httpRequests ->
|
||||
StaticResponses.Continue httpRequests updatedStaticResponsesModel ->
|
||||
let
|
||||
updatedModel : Model route
|
||||
updatedModel =
|
||||
|
@ -17,7 +17,7 @@ import Json.Encode
|
||||
import Pages.GeneratorProgramConfig exposing (GeneratorProgramConfig)
|
||||
import Pages.Internal.Platform.CompatibilityKey
|
||||
import Pages.Internal.Platform.Effect as Effect exposing (Effect)
|
||||
import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses)
|
||||
import Pages.Internal.Platform.StaticResponses as StaticResponses
|
||||
import Pages.Internal.Platform.ToJsPayload as ToJsPayload
|
||||
import Pages.Internal.Script
|
||||
import Pages.StaticHttp.Request
|
||||
@ -33,7 +33,7 @@ type alias Flags =
|
||||
|
||||
{-| -}
|
||||
type alias Model =
|
||||
{ staticResponses : StaticResponses ()
|
||||
{ staticResponses : DataSource ()
|
||||
, errors : List BuildError
|
||||
, allRawResponses : RequestsAndPending
|
||||
, done : Bool
|
||||
@ -323,7 +323,7 @@ initLegacy :
|
||||
-> ( Model, Effect )
|
||||
initLegacy execute { staticHttpCache } =
|
||||
let
|
||||
staticResponses : StaticResponses ()
|
||||
staticResponses : DataSource ()
|
||||
staticResponses =
|
||||
StaticResponses.renderApiRequest execute
|
||||
|
||||
@ -383,11 +383,11 @@ update msg model =
|
||||
|
||||
nextStepToEffect :
|
||||
Model
|
||||
-> ( StaticResponses (), StaticResponses.NextStep route () )
|
||||
-> StaticResponses.NextStep route ()
|
||||
-> ( Model, Effect )
|
||||
nextStepToEffect model ( updatedStaticResponsesModel, nextStep ) =
|
||||
nextStepToEffect model nextStep =
|
||||
case nextStep of
|
||||
StaticResponses.Continue httpRequests ->
|
||||
StaticResponses.Continue httpRequests updatedStaticResponsesModel ->
|
||||
let
|
||||
updatedModel : Model
|
||||
updatedModel =
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), StaticResponses, batchUpdate, empty, nextStep, renderApiRequest)
|
||||
module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), batchUpdate, empty, nextStep, renderApiRequest)
|
||||
|
||||
import BuildError exposing (BuildError)
|
||||
import DataSource exposing (DataSource)
|
||||
@ -9,25 +9,16 @@ import Pages.StaticHttpRequest as StaticHttpRequest
|
||||
import RequestsAndPending exposing (RequestsAndPending)
|
||||
|
||||
|
||||
type StaticResponses a
|
||||
= ApiRequest (StaticHttpResult a)
|
||||
|
||||
|
||||
type StaticHttpResult a
|
||||
= NotFetched (DataSource a)
|
||||
|
||||
|
||||
empty : a -> StaticResponses a
|
||||
empty : a -> DataSource a
|
||||
empty a =
|
||||
ApiRequest
|
||||
(NotFetched (DataSource.succeed a))
|
||||
DataSource.succeed a
|
||||
|
||||
|
||||
renderApiRequest :
|
||||
DataSource response
|
||||
-> StaticResponses response
|
||||
-> DataSource response
|
||||
renderApiRequest request =
|
||||
ApiRequest (NotFetched request)
|
||||
request
|
||||
|
||||
|
||||
batchUpdate :
|
||||
@ -37,12 +28,12 @@ batchUpdate :
|
||||
}
|
||||
->
|
||||
{ model
|
||||
| staticResponses : StaticResponses a
|
||||
| staticResponses : DataSource a
|
||||
, allRawResponses : RequestsAndPending
|
||||
}
|
||||
->
|
||||
{ model
|
||||
| staticResponses : StaticResponses a
|
||||
| staticResponses : DataSource a
|
||||
, allRawResponses : RequestsAndPending
|
||||
}
|
||||
batchUpdate newEntries model =
|
||||
@ -60,30 +51,24 @@ batchUpdate newEntries model =
|
||||
|
||||
|
||||
type NextStep route value
|
||||
= Continue (List HashRequest.Request)
|
||||
= Continue (List HashRequest.Request) (StaticHttpRequest.RawRequest value)
|
||||
| Finish value
|
||||
| FinishedWithErrors (List BuildError)
|
||||
|
||||
|
||||
nextStep :
|
||||
{ model
|
||||
| staticResponses : StaticResponses a
|
||||
| staticResponses : DataSource a
|
||||
, errors : List BuildError
|
||||
, allRawResponses : RequestsAndPending
|
||||
}
|
||||
-> ( StaticResponses a, NextStep route a )
|
||||
-> NextStep route a
|
||||
nextStep ({ allRawResponses, errors } as model) =
|
||||
let
|
||||
staticRequestsStatus : StaticHttpRequest.Status a
|
||||
staticRequestsStatus =
|
||||
allRawResponses
|
||||
|> StaticHttpRequest.cacheRequestResolution request
|
||||
|
||||
request : DataSource a
|
||||
request =
|
||||
case model.staticResponses of
|
||||
ApiRequest (NotFetched request_) ->
|
||||
request_
|
||||
|> StaticHttpRequest.cacheRequestResolution model.staticResponses
|
||||
|
||||
( ( pendingRequests, completedValue ), urlsToPerform, progressedDataSource ) =
|
||||
case staticRequestsStatus of
|
||||
@ -109,7 +94,7 @@ nextStep ({ allRawResponses, errors } as model) =
|
||||
urlsToPerform
|
||||
|> List.Extra.uniqueBy HashRequest.hash
|
||||
in
|
||||
( ApiRequest (NotFetched progressedDataSource), Continue newThing )
|
||||
Continue newThing progressedDataSource
|
||||
|
||||
else
|
||||
let
|
||||
@ -139,11 +124,10 @@ nextStep ({ allRawResponses, errors } as model) =
|
||||
in
|
||||
errors ++ failedRequests
|
||||
in
|
||||
( ApiRequest (NotFetched (DataSource.fail "TODO should never happen"))
|
||||
, if List.length allErrors > 0 then
|
||||
if List.length allErrors > 0 then
|
||||
FinishedWithErrors allErrors
|
||||
|
||||
else
|
||||
else
|
||||
case completedValue of
|
||||
Just completed ->
|
||||
Finish completed
|
||||
@ -152,4 +136,3 @@ nextStep ({ allRawResponses, errors } as model) =
|
||||
FinishedWithErrors
|
||||
[ BuildError.internal "TODO error message"
|
||||
]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user