Skip to content
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

Allow string option transformations for native elements #92

Merged
merged 4 commits into from
Jan 4, 2022

Conversation

davesnx
Copy link
Member

@davesnx davesnx commented Dec 29, 2021

This PR fixes a remaining bug for optional parameters, from #81 (comment)

Was introduced by #84.

@@ -17,3 +17,5 @@ let%component make ~children:(first, second) () =
div ~children:[first; second] ()

let%component make ?(name = "") = div ~children:[name] ()

let%component make () = a ?href:(Some "https://opam.ocaml.org") ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test in test_jsoo_react please? ppx tests will swallow all the things as long as they're syntactically valid, so they don't allow to detect type errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to add them as example, but forgot we have tests that run the browser 💯

Fixed in 7c03b8b (#92)

Copy link
Collaborator

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! thanks for the fix + adding tests 🙏

@@ -92,6 +92,32 @@ let testOptionalProps = () => {
});
};

let testOptionalAttributes = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could call this test testOptionalPropsLowercase and rename the other one to testOptionalPropsUppercase?

@@ -440,7 +440,7 @@ let rec makeFunsForMakePropsBody list args =
let makeAttributeValue ~loc ~isOptional (type_ : Html.attributeType) value =
match (type_, isOptional) with
| String, true ->
[%expr Js_of_ocaml.Js.string ([%e value] : string option)]
[%expr Option.map Js_of_ocaml.Js.string ([%e value] : string option)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not affect any other cases because we only convert the values for the String case right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, any other case is handled with OptDef.

@zbaylin
Copy link
Contributor

zbaylin commented Jan 4, 2022

Just want to chime in and say thanks for this @davesnx ❤️! I bumped up against this when trying to create components that used input, i.e. wanting to only set value if a value for it is passed in above. Will be nice to have this in 🎉

@davesnx davesnx merged commit 2048012 into main Jan 4, 2022
@davesnx davesnx deleted the I-81_fix-option-string branch January 4, 2022 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants