-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving support for polymorphic data types #61
Conversation
@@ -522,6 +522,8 @@ renderDecoderName elmTypeExpr = | |||
parens ("Json.Decode.list " <> parens (renderDecoderName t)) | |||
ETyApp (ETyCon (ETCon "Maybe")) t -> | |||
parens ("Json.Decode.maybe " <> parens (renderDecoderName t)) | |||
ETyApp x y -> | |||
parens (renderDecoderName x <+> renderDecoderName y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously my use case would have been handled by the default case below (which renders spaces and parentheses). This change will render the decoder for x and will then render the decoder for y as an input to the decoder for x.
Example: If x ~ "Either" and y ~ "List String" then x -> jsonDecEither and y -> (Json.Decode.list Json.string) so ETyApp x y -> (jsonDecEither (Json.Decode.list Json.Decode.string).
"jsonDecPolymorphicData : Json.Decode.Decoder a -> Json.Decode.Decoder b -> Json.Decode.Decoder (PolymorphicData a b)\n"<> | ||
"jsonDecPolymorphicData _ _ = Debug.todo \"finish\"\n\n" <> | ||
"jsonDecSomeRecord : Json.Decode.Decoder SomeRecord\n"<> | ||
"jsonDecSomeRecord = Debug.todo \"finish\"\n\n\n")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spoofing the parameterized decoders which would be generated by elm-bridge.
, body = | ||
Http.emptyBody | ||
, expect = | ||
Http.expectJson toMsg ((jsonDecPolymorphicData (Json.Decode.list (Json.Decode.string))) jsonDecSomeRecord) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
red -> green test
This is fantastic! Thank you for the well-made PR. |
Released as 0.7.1 |
Hi!
First off: I'm a huge fan of this library.
In a recent project I encountered a problem where the generated API code for an endpoint which returned an (Either [String] Identifier) was being compiled to:
, expect = jsonDec(Either (List String) Identifier)
which fails to compile. This pull request changes the output in this case to:
, expect = Http.expectJson toMsg ((jsonDecEither (Json.Decode.list (Json.Decode.string))) jsonDecIdentifier)
which matches with the generated decoder.
I built the repo referenced in #58 both as-is and using the changes from this repo and the compilation issue there seems to have gone away.