Update BlazorLibrary template to use newer interop APIs

This commit is contained in:
Steve Sanderson 2018-06-26 14:00:50 +01:00
parent a2bade57c3
commit 2f548f0b27
3 changed files with 12 additions and 9 deletions

View File

@ -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)' != '' " />

View File

@ -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);
}
}

View File

@ -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');
});
}
};