Update BlazorLibrary template to use newer interop APIs
This commit is contained in:
parent
a2bade57c3
commit
2f548f0b27
|
|
@ -9,7 +9,7 @@
|
|||
<MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.2.0-preview1-34353</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>
|
||||
|
||||
<!-- Used only in development when running the template contents directly from source -->
|
||||
<TemplateBlazorPackageVersion>0.4.0-preview1-10300</TemplateBlazorPackageVersion>
|
||||
<TemplateBlazorPackageVersion>0.5.0-preview1-10325</TemplateBlazorPackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Blazor.Browser.Interop;
|
||||
using Microsoft.JSInterop;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlazorLibrary_CSharp
|
||||
{
|
||||
public class ExampleJsInterop
|
||||
{
|
||||
public static string Prompt(string message)
|
||||
public static Task<string> Prompt(string message)
|
||||
{
|
||||
return RegisteredFunction.Invoke<string>(
|
||||
"BlazorLibrary-CSharp.ExampleJsInterop.Prompt",
|
||||
// Implemented in exampleJsInterop.js
|
||||
return JSRuntime.Current.InvokeAsync<string>(
|
||||
"exampleJsFunctions.showPrompt",
|
||||
message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// This file is to show how a library package may provide JavaScript interop features
|
||||
// This file is to show how a library package may provide JavaScript interop features
|
||||
// wrapped in a .NET API
|
||||
|
||||
Blazor.registerFunction('BlazorLibrary-CSharp.ExampleJsInterop.Prompt', function (message) {
|
||||
window.exampleJsFunctions = {
|
||||
showPrompt: function (message) {
|
||||
return prompt(message, 'Type anything here');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue