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

Fix JS output in 'Working with JavaScript objects and values' page #212

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

feihong
Copy link
Collaborator

@feihong feihong commented Dec 19, 2024

I fixed some typos and mistakes on the 'Working with JavaScript objects and values' page, and in the process converted all the JS output from commonjs to es6 (since I used Melange Playground to generate the snippets and all JS output there is es6 now).

@feihong feihong force-pushed the working-with-js-obj-val branch from c273e71 to 486c3f9 Compare December 20, 2024 04:07
@feihong feihong force-pushed the working-with-js-obj-val branch from 486c3f9 to 98722f8 Compare December 22, 2024 03:48
@feihong feihong changed the title Fix JS output in 'Working with JavaScript objects and values" page Fix JS output in 'Working with JavaScript objects and values' page Jan 3, 2025
@feihong feihong marked this pull request as ready for review January 3, 2025 23:47
@@ -202,7 +202,7 @@ manual](https://v2.ocaml.org/manual/objectexamples.html).
We have already explored one approach for creating JavaScript object literals by
using [`Js.t` values and the `mel.obj` extension](#using-js-t-objects).

Melange additionally offers the `@mel.obj` attribute, which can be used in
Melange additionally offers the `mel.obj` attribute, which can be used in
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the @ from attribute names that was added in previous PR.

position. Not having the last param `unit` would lead to a warning, which is
explained in detail [in the OCaml
documentation](https://ocaml.org/docs/labels#warning-this-optional-argument-cannot-be-erased).
> **Note**: in this particular case, a final param of type unit, `()` must be
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jchavarri I wonder if we can migrate to new syntax for custom containers in vitepress? They are more pleasant to edit, but they do have different styling than this old syntax.

@@ -1076,20 +1075,20 @@ not prevent consumers of the external function from calling it using values that
are unsupported by the JavaScript function. Let’s see how we can use polymorphic
variants to avoid runtime errors.

If the values are strings, we can use the `mel.string` attribute:
If the values are strings, we can directly use polymorphic variants:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed this because Melange compiler now generates warning if you try to use mel.string in this way

used, and the `##` infix operator allows to read from the object properties:
the properties inside them.

- To create values, use the <span class="text-ocaml">`[%mel.obj]` extension
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added reasonml-specific text since formatting let john = [%mel.obj { name : "john", age : 99 }]; in Reason syntax will convert it to just let john = { "name": "john", "age": 99 }

@feihong feihong requested review from jchavarri and davesnx January 4, 2025 00:39
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.

1 participant