[Blazor] synchronous-js-interop-call-js.md - fully synchronous code sample (#34332)

pull/34334/head
Robert Haken 2024-12-11 01:32:30 +01:00 committed by GitHub
parent 1e42860b21
commit 6d40da43e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 5 deletions

View File

@ -24,7 +24,7 @@ When working with <xref:Microsoft.JSInterop.IJSObjectReference> in ASP.NET Core
```razor
@inject IJSRuntime JS
@implements IAsyncDisposable
@implements IDisposable
...
@ -36,18 +36,20 @@ When working with <xref:Microsoft.JSInterop.IJSObjectReference> in ASP.NET Core
{
if (firstRender)
{
module = await JS.InvokeAsync<IJSInProcessObjectReference>("import",
"./scripts.js");
var jsInProcess = (IJSInProcessRuntime)JS;
module = await jsInProcess.Invoke<IJSInProcessObjectReference>("import",
"./scripts.js");
var value = module.Invoke<string>("javascriptFunctionIdentifier");
}
}
...
async ValueTask IAsyncDisposable.DisposeAsync()
void IDisposable.Dispose()
{
if (module is not null)
{
await module.DisposeAsync();
await module.Dispose();
}
}
}