Skip to content

Commit

Permalink
Update JS module code for release (#27534)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Nov 8, 2022
1 parent 2e85bb7 commit 6025761
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions aspnetcore/client-side/dotnet-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,7 @@ In the following example:

* `exports.MyClass.Greeting()` calls into .NET (`MyClass.Greeting`) from JS. The `Greeting` C# method returns a string that includes the result of calling the `window.location.href` function. The `Greeting` method is shown later in this section.

* `runMainAndExit` runs `Program.Main`.

<!--
NOTE: THE FOLLOWING CODE IS CHANGING FOR RELEASE:
https://github.com/dotnet/runtime/blob/release/7.0/src/mono/wasm/templates/templates/browser/main.js
For example, the runMainAndExit() is changing to dotnet.run().
This is tracked on the 7.0 doc tracking issue at https://github.com/dotnet/AspNetCore.Docs/issues/26364.
-->
* `dotnet.run()` runs `Program.Main`.

JS module:

Expand All @@ -148,7 +136,7 @@ import { dotnet } from './dotnet.js'
const is_browser = typeof window != "undefined";
if (!is_browser) throw new Error(`Expected to be running in a browser`);

const { setModuleImports, getAssemblyExports, getConfig, runMainAndExit } =
const { setModuleImports, getAssemblyExports, getConfig } =
await dotnet.create();

setModuleImports("main.js", {
Expand All @@ -164,8 +152,8 @@ const exports = await getAssemblyExports(config.mainAssemblyName);
const text = exports.MyClass.Greeting();
console.log(text);

document.getElementById("out").innerHTML = `${text}`;
await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);
document.getElementById("out").innerHTML = text;
await dotnet.run();
```

To import a JS function so it can be called from C#, use the new `JSImportAttribute` on a matching method signature. The first parameter to the `JSImportAttribute` is the name of the JS function to import and the second parameter is the name of the module.
Expand Down

0 comments on commit 6025761

Please sign in to comment.