From 5bccac05fc4ee3ded5c5d2f54a8be6a2287b6c11 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Fri, 6 Jul 2018 14:10:55 +0100 Subject: [PATCH] Refactoring to prepare for remote rendering. - Prepare for building multiple entrypoint variants of the .js library - Use async interop more consistently for rendering and event handling - Add binary serializer for RenderBatch with tests --- ...rosoft.AspNetCore.Blazor.Browser.JS.csproj | 4 +- .../src/{Boot.ts => Boot.WebAssembly.ts} | 15 +- .../src/Environment.ts | 11 +- .../src/GlobalExports.ts | 27 +- .../src/Rendering/BrowserRenderer.ts | 17 +- .../src/Services/UriHelper.ts | 19 +- .../webpack.config.js | 4 +- .../BrowserRendererEventDispatcher.cs | 45 ++- .../Services/BrowserUriHelper.cs | 6 +- .../Core/IndexHtmlWriter.cs | 2 +- .../Microsoft.AspNetCore.Blazor.Build.nuspec | 4 +- .../ReferenceFromSource.props | 2 +- .../targets/Blazor.MonoRuntime.props | 2 +- .../Circuits/RenderBatchWriter.cs | 249 ++++++++++++++ .../Microsoft.AspNetCore.Blazor.Server.csproj | 4 + .../Properties/AssemblyInfo.cs | 3 +- .../IndexHtmlWriterTest.cs | 4 +- .../CircuitSynchronizationContextTest.cs | 2 +- .../Circuits/RenderBatchWriterTest.cs | 311 ++++++++++++++++++ test/testapps/BasicTestApp/Program.cs | 1 + test/testapps/BasicTestApp/wwwroot/index.html | 3 +- 21 files changed, 667 insertions(+), 68 deletions(-) rename src/Microsoft.AspNetCore.Blazor.Browser.JS/src/{Boot.ts => Boot.WebAssembly.ts} (73%) create mode 100644 src/Microsoft.AspNetCore.Blazor.Server/Circuits/RenderBatchWriter.cs create mode 100644 test/Microsoft.AspnetCore.Blazor.Server.Test/Circuits/RenderBatchWriterTest.cs diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/Microsoft.AspNetCore.Blazor.Browser.JS.csproj b/src/Microsoft.AspNetCore.Blazor.Browser.JS/Microsoft.AspNetCore.Blazor.Browser.JS.csproj index 71ad62f790..9b25255af7 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/Microsoft.AspNetCore.Blazor.Browser.JS.csproj +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/Microsoft.AspNetCore.Blazor.Browser.JS.csproj @@ -24,11 +24,11 @@ - + - + diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.WebAssembly.ts similarity index 73% rename from src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts rename to src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.WebAssembly.ts index a483e8283d..364d896ed1 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.WebAssembly.ts @@ -1,9 +1,20 @@ import '../../Microsoft.JSInterop/JavaScriptRuntime/src/Microsoft.JSInterop'; -import { platform } from './Environment'; -import { getAssemblyNameFromUrl } from './Platform/Url'; import './GlobalExports'; +import * as Environment from './Environment'; +import { monoPlatform } from './Platform/Mono/MonoPlatform'; +import { getAssemblyNameFromUrl } from './Platform/Url'; +import { renderBatch } from './Rendering/Renderer'; +import { RenderBatch } from './Rendering/RenderBatch/RenderBatch'; +import { SharedMemoryRenderBatch } from './Rendering/RenderBatch/SharedMemoryRenderBatch'; +import { Pointer } from './Platform/Platform'; async function boot() { + // Configure environment for execution under Mono WebAssembly with shared-memory rendering + const platform = Environment.setPlatform(monoPlatform); + window['Blazor']._internal.renderBatch = (browserRendererId: number, batchAddress: Pointer) => { + renderBatch(browserRendererId, new SharedMemoryRenderBatch(batchAddress)); + }; + // Read startup config from the