Skip to content

Intl types: simplify bindings for constructors / functions with optional arguments #198

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

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

cknitt
Copy link
Member

@cknitt cknitt commented Feb 25, 2024

Now that we can have functions with optional arguments without a trailing () in ReScript 11 uncurried mode, bindings can be simplified to a single make function (and the same for supportedLocalesOf) with nice ergonomics.

I also think we can drop the distinction between passing a single locale and an array of locales. Just pass an array always.

One minor downside are trailing undefined params in the JS output. This is probably something we should improve in the compiler, but it shouldn't do any harm here.

@zth @illusionalsagacity @glennsl For now I just did it for Intl.Collator. If this looks good to you, I would extend it to the other types.

(The first commit just removes duplicate build artifacts that were in test/intl plus test/Intl).

@cknitt cknitt requested a review from zth February 25, 2024 14:37
@zth
Copy link
Collaborator

zth commented Feb 25, 2024

I like this, and this is a conversion we should do for more APIs. As in combine variants that can be a single function with optional args now with v11.

We should optimize the compiler to not print the undefineds unless needed. There's an issue for it somewhere and me and @cristianoc have been chatting about it too before.

Copy link
Contributor

@glennsl glennsl 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 to me!

@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.Collator"

@val external supportedLocalesOf: array<string> => t = "Intl.Collator.supportedLocalesOf"
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Collator"
Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative here could be:

Suggested change
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Collator"
@new external make: (array<string>, ~options: options=?) => t = "Intl.Collator"

as passing an empty array is effectively the same This would be more convenient if the common case is to pass one or more locales, but less so if it the default is more common. Not sure which is though.

@cknitt cknitt force-pushed the intl-constructors branch from 3a8757f to 8a425e7 Compare March 2, 2024 16:43
@cknitt cknitt marked this pull request as ready for review March 2, 2024 16:45
@cknitt cknitt changed the title WIP: Intl types: simplify bindings for constructors / functions with optional arguments Intl types: simplify bindings for constructors / functions with optional arguments Mar 2, 2024
@cknitt
Copy link
Member Author

cknitt commented Mar 2, 2024

@zth @illusionalsagacity @glennsl For now I just did it for Intl.Collator. If this looks good to you, I would extend it to the other types.

Extended to the remaining Intl types, please re-review.

@cknitt cknitt requested review from glennsl and zth March 2, 2024 16:47
Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

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

Great! Merge away.

@cknitt cknitt force-pushed the intl-constructors branch from a319c66 to 40431ec Compare March 4, 2024 07:52
@cknitt cknitt merged commit d664fe2 into main Mar 4, 2024
@cknitt cknitt deleted the intl-constructors branch March 4, 2024 07:54
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