Use record for parameters in Pages.Generate to make it more manageable to keep track of names.

This commit is contained in:
Dillon Kearns 2023-01-13 15:53:43 -08:00
parent d6efc56152
commit 2ddd0c89e8
3 changed files with 200 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@ -86,13 +86,13 @@ buildFile moduleName =
} }
|> Pages.Generate.buildWithLocalState |> Pages.Generate.buildWithLocalState
{ view = { view =
\maybeUrl sharedModel model app -> \{ maybeUrl, sharedModel, model, app } ->
Gen.View.make_.view Gen.View.make_.view
{ title = moduleName |> String.join "." |> Elm.string { title = moduleName |> String.join "." |> Elm.string
, body = Elm.list [ Gen.Html.Styled.text "Here is your generated page!!!" ] , body = Elm.list [ Gen.Html.Styled.text "Here is your generated page!!!" ]
} }
, update = , update =
\pageUrl sharedModel app msg model -> \{ pageUrl, sharedModel, app, msg, model } ->
Elm.Case.custom msg Elm.Case.custom msg
(Elm.Annotation.named [] "Msg") (Elm.Annotation.named [] "Msg")
[ Elm.Case.branch0 "NoOp" [ Elm.Case.branch0 "NoOp"
@ -103,13 +103,13 @@ buildFile moduleName =
) )
] ]
, init = , init =
\pageUrl sharedModel app -> \{ pageUrl, sharedModel, app } ->
Elm.tuple (Elm.record []) Elm.tuple (Elm.record [])
(Gen.Effect.none (Gen.Effect.none
|> Elm.withType effectType |> Elm.withType effectType
) )
, subscriptions = , subscriptions =
\maybePageUrl routeParams path sharedModel model -> \{ maybePageUrl, routeParams, path, sharedModel, model } ->
Gen.Platform.Sub.none Gen.Platform.Sub.none
, model = , model =
Alias (Elm.Annotation.record []) Alias (Elm.Annotation.record [])

View File

@ -128,7 +128,7 @@ single input =
{-| -} {-| -}
buildNoState : buildNoState :
{ view : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { view : { maybeUrl : Elm.Expression, sharedModel : Elm.Expression, app : Elm.Expression } -> Elm.Expression
} }
-> Builder -> Builder
-> Elm.File -> Elm.File
@ -136,7 +136,13 @@ buildNoState definitions builder_ =
case builder_ of case builder_ of
ServerRender builder -> ServerRender builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = \_ -> definitions.view { view =
\maybeUrl sharedModel _ app ->
definitions.view
{ maybeUrl = maybeUrl
, sharedModel = sharedModel
, app = app
}
, localState = Nothing , localState = Nothing
, data = builder.data |> Tuple.second , data = builder.data |> Tuple.second
, action = builder.action |> Tuple.second |> Action , action = builder.action |> Tuple.second |> Action
@ -151,7 +157,13 @@ buildNoState definitions builder_ =
PreRender builder -> PreRender builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = \_ -> definitions.view { view =
\maybeUrl sharedModel _ app ->
definitions.view
{ maybeUrl = maybeUrl
, sharedModel = sharedModel
, app = app
}
, localState = Nothing , localState = Nothing
, data = builder.data |> Tuple.second , data = builder.data |> Tuple.second
, action = builder.pages |> Pages , action = builder.pages |> Pages
@ -170,10 +182,30 @@ buildNoState definitions builder_ =
{-| -} {-| -}
buildWithLocalState : buildWithLocalState :
{ view : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { view :
, update : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { maybeUrl : Elm.Expression, sharedModel : Elm.Expression, model : Elm.Expression, app : Elm.Expression } -> Elm.Expression
, init : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression , update :
, subscriptions : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { pageUrl : Elm.Expression
, sharedModel : Elm.Expression
, app : Elm.Expression
, msg : Elm.Expression
, model : Elm.Expression
}
-> Elm.Expression
, init :
{ pageUrl : Elm.Expression
, sharedModel : Elm.Expression
, app : Elm.Expression
}
-> Elm.Expression
, subscriptions :
{ maybePageUrl : Elm.Expression
, routeParams : Elm.Expression
, path : Elm.Expression
, sharedModel : Elm.Expression
, model : Elm.Expression
}
-> Elm.Expression
, msg : Type , msg : Type
, model : Type , model : Type
} }
@ -183,12 +215,41 @@ buildWithLocalState definitions builder_ =
case builder_ of case builder_ of
ServerRender builder -> ServerRender builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = definitions.view { view =
\maybeUrl sharedModel model app ->
definitions.view
{ maybeUrl = maybeUrl
, sharedModel = sharedModel
, model = model
, app = app
}
, localState = , localState =
Just Just
{ update = definitions.update { update =
, init = definitions.init \pageUrl sharedModel app msg model ->
, subscriptions = definitions.subscriptions definitions.update
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
, msg = msg
, model = model
}
, init =
\pageUrl sharedModel app ->
definitions.init
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
}
, subscriptions =
\maybePageUrl routeParams path sharedModel model ->
definitions.subscriptions
{ maybePageUrl = maybePageUrl
, routeParams = routeParams
, path = path
, sharedModel = sharedModel
, model = model
}
, state = LocalState , state = LocalState
} }
, data = builder.data |> Tuple.second , data = builder.data |> Tuple.second
@ -204,12 +265,41 @@ buildWithLocalState definitions builder_ =
PreRender builder -> PreRender builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = definitions.view { view =
\maybeUrl sharedModel model app ->
definitions.view
{ maybeUrl = maybeUrl
, sharedModel = sharedModel
, model = model
, app = app
}
, localState = , localState =
Just Just
{ update = definitions.update { update =
, init = definitions.init \pageUrl sharedModel app msg model ->
, subscriptions = definitions.subscriptions definitions.update
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
, msg = msg
, model = model
}
, init =
\pageUrl sharedModel app ->
definitions.init
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
}
, subscriptions =
\maybePageUrl routeParams path sharedModel model ->
definitions.subscriptions
{ maybePageUrl = maybePageUrl
, routeParams = routeParams
, path = path
, sharedModel = sharedModel
, model = model
}
, state = LocalState , state = LocalState
} }
, data = builder.data |> Tuple.second , data = builder.data |> Tuple.second
@ -229,10 +319,30 @@ buildWithLocalState definitions builder_ =
{-| -} {-| -}
buildWithSharedState : buildWithSharedState :
{ view : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { view :
, update : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { maybeUrl : Elm.Expression, sharedModel : Elm.Expression, model : Elm.Expression, app : Elm.Expression } -> Elm.Expression
, init : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression , update :
, subscriptions : Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression -> Elm.Expression { pageUrl : Elm.Expression
, sharedModel : Elm.Expression
, app : Elm.Expression
, msg : Elm.Expression
, model : Elm.Expression
}
-> Elm.Expression
, init :
{ pageUrl : Elm.Expression
, sharedModel : Elm.Expression
, app : Elm.Expression
}
-> Elm.Expression
, subscriptions :
{ maybePageUrl : Elm.Expression
, routeParams : Elm.Expression
, path : Elm.Expression
, sharedModel : Elm.Expression
, model : Elm.Expression
}
-> Elm.Expression
, msg : Type , msg : Type
, model : Type , model : Type
} }
@ -242,12 +352,41 @@ buildWithSharedState definitions builder_ =
case builder_ of case builder_ of
ServerRender builder -> ServerRender builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = definitions.view { view =
\maybeUrl sharedModel model app ->
definitions.view
{ maybeUrl = maybeUrl
, sharedModel = sharedModel
, model = model
, app = app
}
, localState = , localState =
Just Just
{ update = definitions.update { update =
, init = definitions.init \pageUrl sharedModel app msg model ->
, subscriptions = definitions.subscriptions definitions.update
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
, msg = msg
, model = model
}
, init =
\pageUrl sharedModel app ->
definitions.init
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
}
, subscriptions =
\maybePageUrl routeParams path sharedModel model ->
definitions.subscriptions
{ maybePageUrl = maybePageUrl
, routeParams = routeParams
, path = path
, sharedModel = sharedModel
, model = model
}
, state = SharedState , state = SharedState
} }
, data = builder.data |> Tuple.second , data = builder.data |> Tuple.second
@ -263,12 +402,41 @@ buildWithSharedState definitions builder_ =
PreRender builder -> PreRender builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = definitions.view { view =
\maybeUrl sharedModel model app ->
definitions.view
{ maybeUrl = maybeUrl
, sharedModel = sharedModel
, model = model
, app = app
}
, localState = , localState =
Just Just
{ update = definitions.update { update =
, init = definitions.init \pageUrl sharedModel app msg model ->
, subscriptions = definitions.subscriptions definitions.update
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
, msg = msg
, model = model
}
, init =
\pageUrl sharedModel app ->
definitions.init
{ pageUrl = pageUrl
, sharedModel = sharedModel
, app = app
}
, subscriptions =
\maybePageUrl routeParams path sharedModel model ->
definitions.subscriptions
{ maybePageUrl = maybePageUrl
, routeParams = routeParams
, path = path
, sharedModel = sharedModel
, model = model
}
, state = SharedState , state = SharedState
} }
, data = builder.data |> Tuple.second , data = builder.data |> Tuple.second