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

Add test for mel.as in mel.set external #705

Merged
merged 2 commits into from
Aug 31, 2023
Merged

Conversation

jchavarri
Copy link
Member

@jchavarri jchavarri commented Aug 29, 2023

There used to be a way to rename polyvars in externals by using bs.set in combination with bs.as, as documented in melange.re#using-polymorphic-variants-to-bind-to-enums, e.g:

type document
type style

external document : document = "document" [@@bs.val]
external get_by_id : document -> string -> Dom.element = "getElementById"
  [@@bs.send]
external style : Dom.element -> style = "style" [@@bs.get]
external transition_timing_function :
  style ->
  [ `ease
  | `easeIn [@bs.as "ease-in"]
  | `easeOut [@bs.as "ease-out"]
  | `easeInOut [@bs.as "ease-in-out"]
  | `linear
  ] ->
  unit = "transitionTimingFunction"
  [@@bs.set]

let element_style = style (get_by_id document "my-id")
let () = transition_timing_function element_style `easeIn

I can't make this code work with the latest version, see the test included in the PR. In any combination of attributes (bs.sel, mel.set, bs.as, as, mel.as) the resulting JavaScript code does not honor the as attribute to rename the polyvar.

@jchavarri
Copy link
Member Author

@anmonteiro pointed out I as missing mel.string, updated the tests to reflect the 2 situations (with and without mel.string).

@jchavarri
Copy link
Member Author

See related: #578

@anmonteiro
Copy link
Member

This is a good test case to have when we get around to implementing #578. Thanks!

@anmonteiro anmonteiro merged commit c9809e1 into main Aug 31, 2023
4 checks passed
@anmonteiro anmonteiro deleted the test-mel-as-in-externals branch August 31, 2023 17:14
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.

2 participants