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

JavaScript usage documentation improvements #3025

Merged
merged 3 commits into from
Jun 9, 2023

Conversation

jonsequitur
Copy link
Contributor

This addresses #2928.

@jonsequitur jonsequitur force-pushed the docs-improvements-2023-06-08 branch from aec8316 to 8047288 Compare June 8, 2023 22:58
@@ -96,7 +179,7 @@ When you run this code, you can see that the original C# variable gets overwritt

<img width="503" alt="image" src="https://user-images.githubusercontent.com/547415/211661641-057e29fc-8048-4910-983f-14d8380dca8b.png">

One notable detail is that the type of the new C# variable has changed from the original declaration. It was originally declared as `int[]`, but after sharing the array back from JavaScript, the C# kernel has a variable called `array` which is of type `JsonDocument`. Because the JavaScript kernel runs in a different process from the .NET subkernels, sharing happens via JSON serialization. Complex types shared from JavaScript to .NET are sent as JSON and deserialized using `System.Text.Json`. There are a few simple types that will be shared as their intuitive .NET counterparts.
One notable detail here is that the type of the new C# variable has changed from the original declaration. It was originally declared as `int[]`, but after sharing the array back from JavaScript, the C# kernel has a variable called `array` which is of type `JsonDocument`. Because the JavaScript kernel runs in a different process from the .NET subkernels, sharing happens via JSON serialization. Complex types shared from JavaScript to .NET are sent as JSON and deserialized using `System.Text.Json`. There are a few simple types that will be shared as their intuitive .NET counterparts.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change the screenshot for the above example to use #!set instead of #!share? That may work better since the sharing is by value by default with #!set (and since there will be a nice error if someone tries to share by reference for JavaScript).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call.


```javascript
const doSomething = async () => {
// Your code here
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: Does some alternate approach exist that would allow us to execute some arbitrary piece of supplied JavaScript within a top-level scope? I am sure there is good reason to select the above approach - but was just curious if there are alternatives and what downsides these alternatives might have.

Copy link
Contributor

@shyamnamboodiripad shyamnamboodiripad 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 👍🏾

@jonsequitur jonsequitur merged commit 3be49ef into dotnet:main Jun 9, 2023
@colombod colombod added the Area-Documentation Improvements or additions to documentation label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants