From 5cb544ece8ddeaf9e3ae222b6ae6cc2ec97cd209 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Wed, 23 May 2018 14:38:30 -0700 Subject: [PATCH] Improved interoperability * Add support for invoking async JavaScript functions from .NET. * Add support for invoking .NET methods from JavaScript. * Add support for invoking async .NET methods from JavaScript. --- .../package-lock.json | 18 +- .../src/Boot.ts | 2 +- .../src/GlobalExports.ts | 3 + .../src/Interop/InternalRegisteredFunction.ts | 5 +- .../InvokeDotNetMethodWithJsonMarshalling.ts | 190 ++++++++ ...keJavaScriptFunctionWithJsonMarshalling.ts | 66 +++ .../src/Interop/InvokeWithJsonMarshalling.ts | 27 -- .../src/Platform/Mono/MonoPlatform.ts | 2 +- .../src/Platform/Platform.ts | 2 +- .../webpack.config.js | 2 +- .../Interop/ArgumentList.cs | 260 +++++++++++ .../Interop/InvocationResult.cs | 25 + .../Interop/InvokeDotNetFromJavaScript.cs | 163 +++++++ .../Interop/MethodIdentifier.cs | 53 +++ .../Interop/MethodInvocationOptions.cs | 21 + .../Interop/RegisteredFunction.cs | 86 +++- .../Interop/TaskCallbacks.cs | 44 ++ .../Interop/TaskResultUtil.cs | 33 ++ .../Interop/TypeIdentifier.cs | 22 + .../Interop/JavaScriptInvokeTests.cs | 429 ++++++++++++++++++ .../Tests/InteropTest.cs | 105 +++++ .../BasicTestApp/InteropComponent.cshtml | 96 ++++ .../InteropTest/ComplexParameter.cs | 13 + .../InteropTest/JavaScriptInterop.cs | 360 +++++++++++++++ .../BasicTestApp/InteropTest/Segment.cs | 12 + test/testapps/BasicTestApp/Program.cs | 2 +- test/testapps/BasicTestApp/wwwroot/index.html | 3 + .../BasicTestApp/wwwroot/js/jsinteroptests.js | 176 +++++++ 28 files changed, 2172 insertions(+), 48 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Interop/InvokeDotNetMethodWithJsonMarshalling.ts create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Interop/InvokeJavaScriptFunctionWithJsonMarshalling.ts delete mode 100644 src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Interop/InvokeWithJsonMarshalling.ts create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/ArgumentList.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/InvocationResult.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/InvokeDotNetFromJavaScript.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/MethodIdentifier.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/MethodInvocationOptions.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/TaskCallbacks.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/TaskResultUtil.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser/Interop/TypeIdentifier.cs create mode 100644 test/Microsoft.AspNetCore.Blazor.Browser.Test/Interop/JavaScriptInvokeTests.cs create mode 100644 test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/InteropTest.cs create mode 100644 test/testapps/BasicTestApp/InteropComponent.cshtml create mode 100644 test/testapps/BasicTestApp/InteropTest/ComplexParameter.cs create mode 100644 test/testapps/BasicTestApp/InteropTest/JavaScriptInterop.cs create mode 100644 test/testapps/BasicTestApp/InteropTest/Segment.cs create mode 100644 test/testapps/BasicTestApp/wwwroot/js/jsinteroptests.js diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/package-lock.json b/src/Microsoft.AspNetCore.Blazor.Browser.JS/package-lock.json index cf7f6a5473..b74213bea2 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/package-lock.json +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/package-lock.json @@ -1830,15 +1830,6 @@ "xtend": "4.0.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -1872,6 +1863,15 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts index 065c711523..f80ea87a0c 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts @@ -1,4 +1,4 @@ -import { platform } from './Environment'; +import { platform } from './Environment'; import { getAssemblyNameFromUrl } from './Platform/DotNet'; import './Rendering/Renderer'; import './Services/Http'; diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/GlobalExports.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/GlobalExports.ts index 6278b3f893..576ab2c861 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/GlobalExports.ts +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/GlobalExports.ts @@ -1,6 +1,7 @@ import { platform } from './Environment' import { registerFunction } from './Interop/RegisteredFunction'; import { navigateTo } from './Services/UriHelper'; +import { invokeDotNetMethod, invokeDotNetMethodAsync } from './Interop/InvokeDotNetMethodWithJsonMarshalling'; if (typeof window !== 'undefined') { // When the library is loaded in a browser via a + +