mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 23:12:22 +03:00
Remove unused.
This commit is contained in:
parent
9d8320d5fd
commit
30cbc970de
99
src/Form.elm
99
src/Form.elm
@ -5,7 +5,6 @@ module Form exposing
|
||||
, renderHtml, renderStyledHtml
|
||||
, FinalForm, withGetMethod
|
||||
, Errors
|
||||
, parse, runOneOfServerSide, runServerSide
|
||||
, runOneOfServerSideWithServerValidations
|
||||
, AppContext
|
||||
, FieldDefinition(..)
|
||||
@ -677,34 +676,6 @@ mergeErrors errors1 errors2 =
|
||||
Dict.empty
|
||||
|
||||
|
||||
{-| -}
|
||||
parse :
|
||||
AppContext app
|
||||
-> data
|
||||
-> Form error (Validation error parsed named) data (Context error data -> view)
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
parse app data (Form _ parser _) =
|
||||
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
||||
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
||||
let
|
||||
parsed :
|
||||
{ result : ( Validation error parsed named, Dict String (List error) )
|
||||
, view : Context error data -> view
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
parser (Just data) thisFormState
|
||||
|
||||
thisFormState : Form.FormState
|
||||
thisFormState =
|
||||
app.pageFormState
|
||||
-- TODO remove hardcoding
|
||||
|> Dict.get "test"
|
||||
|> Maybe.withDefault initFormState
|
||||
in
|
||||
parsed |> mergeResults |> unwrapValidation
|
||||
|
||||
|
||||
{-| -}
|
||||
parse2 :
|
||||
AppContext app
|
||||
@ -747,45 +718,6 @@ insertIfNonempty key values dict =
|
||||
|> Dict.insert key values
|
||||
|
||||
|
||||
{-| -}
|
||||
runServerSide :
|
||||
List ( String, String )
|
||||
-> Form error (Validation error parsed named) data (Context error data -> view)
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
runServerSide rawFormData (Form _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result :
|
||||
( Validation error parsed named
|
||||
, Dict String (List error)
|
||||
)
|
||||
, view : Context error data -> view
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
parser Nothing thisFormState
|
||||
|
||||
thisFormState : Form.FormState
|
||||
thisFormState =
|
||||
{ initFormState
|
||||
| fields =
|
||||
rawFormData
|
||||
|> List.map
|
||||
(Tuple.mapSecond
|
||||
(\value ->
|
||||
{ value = value
|
||||
, status = Form.NotVisited
|
||||
}
|
||||
)
|
||||
)
|
||||
|> Dict.fromList
|
||||
}
|
||||
in
|
||||
parsed
|
||||
|> mergeResults
|
||||
|> unwrapValidation
|
||||
|
||||
|
||||
{-| -}
|
||||
runServerSide2 :
|
||||
List ( String, String )
|
||||
@ -906,37 +838,6 @@ unwrapValidation (Pages.Internal.Form.Validation viewField name ( maybeParsed, e
|
||||
( maybeParsed, errors )
|
||||
|
||||
|
||||
{-| -}
|
||||
runOneOfServerSide :
|
||||
List ( String, String )
|
||||
-> List (Form error (Validation error parsed named) data (Context error data -> view))
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
runOneOfServerSide rawFormData parsers =
|
||||
case parsers of
|
||||
firstParser :: remainingParsers ->
|
||||
let
|
||||
thing : ( Maybe parsed, List ( String, List error ) )
|
||||
thing =
|
||||
runServerSide rawFormData firstParser
|
||||
|> Tuple.mapSecond
|
||||
(\errors ->
|
||||
errors
|
||||
|> Dict.toList
|
||||
|> List.filter (Tuple.second >> List.isEmpty >> not)
|
||||
)
|
||||
in
|
||||
case thing of
|
||||
( Just parsed, [] ) ->
|
||||
( Just parsed, Dict.empty )
|
||||
|
||||
_ ->
|
||||
runOneOfServerSide rawFormData remainingParsers
|
||||
|
||||
[] ->
|
||||
-- TODO need to pass errors
|
||||
( Nothing, Dict.empty )
|
||||
|
||||
|
||||
{-| -}
|
||||
runOneOfServerSide2 :
|
||||
List ( String, String )
|
||||
|
@ -1,7 +1,6 @@
|
||||
module Server.Request exposing
|
||||
( Parser
|
||||
, succeed, fromResult, skip
|
||||
, formData, formDataWithoutServerValidation
|
||||
, rawFormData
|
||||
, method, rawBody, allCookies, rawHeaders, queryParams
|
||||
, requestTime, optionalHeader, expectContentType, expectJsonBody
|
||||
@ -919,72 +918,6 @@ formDataWithoutServerValidation2 formParsers =
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
formDataWithoutServerValidation :
|
||||
List (Form.Form error (Validation error combined named) data (Form.Context error data -> viewFn))
|
||||
-> Parser (Result { fields : List ( String, String ), errors : Dict String (List error) } combined)
|
||||
formDataWithoutServerValidation formParsers =
|
||||
rawFormData
|
||||
|> andThen
|
||||
(\rawFormData_ ->
|
||||
let
|
||||
( maybeDecoded, errors ) =
|
||||
Form.runOneOfServerSide
|
||||
rawFormData_
|
||||
formParsers
|
||||
in
|
||||
case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
|
||||
( Just decoded, Nothing ) ->
|
||||
succeed (Ok decoded)
|
||||
|
||||
( _, maybeErrors ) ->
|
||||
Err
|
||||
{ fields = rawFormData_
|
||||
, errors =
|
||||
maybeErrors
|
||||
|> Maybe.map List.NonEmpty.toList
|
||||
|> Maybe.withDefault []
|
||||
|> Dict.fromList
|
||||
}
|
||||
|> succeed
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
formData :
|
||||
List (Form.Form error (Validation error combined named) data (Form.Context error data -> viewFn))
|
||||
-> Parser (DataSource (Result { fields : List ( String, String ), errors : Dict String (List error) } combined))
|
||||
formData formParsers =
|
||||
rawFormData
|
||||
|> andThen
|
||||
(\rawFormData_ ->
|
||||
let
|
||||
( maybeDecoded, errorsDataSource ) =
|
||||
Form.runOneOfServerSideWithServerValidations
|
||||
rawFormData_
|
||||
formParsers
|
||||
in
|
||||
errorsDataSource
|
||||
|> DataSource.map
|
||||
(\errors ->
|
||||
case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
|
||||
( Just decoded, Nothing ) ->
|
||||
Ok decoded
|
||||
|
||||
( _, maybeErrors ) ->
|
||||
Err
|
||||
{ fields = rawFormData_
|
||||
, errors =
|
||||
maybeErrors
|
||||
|> Maybe.map List.NonEmpty.toList
|
||||
|> Maybe.withDefault []
|
||||
|> Dict.fromList
|
||||
}
|
||||
)
|
||||
|> succeed
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
formData2 :
|
||||
List
|
||||
|
@ -3,7 +3,7 @@ module FormTests exposing (all)
|
||||
import Date exposing (Date)
|
||||
import Dict
|
||||
import Expect
|
||||
import Form exposing (Form, FormNew)
|
||||
import Form exposing (FormNew)
|
||||
import Form.Field as Field
|
||||
import Form.Validation as Validation exposing (Validation)
|
||||
import Test exposing (Test, describe, test)
|
||||
|
Loading…
Reference in New Issue
Block a user