Skip to content

Commit 9208509

Browse files
committed
Address feedback from peer review
1 parent fa9f6f0 commit 9208509

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

src/Components/Components/src/Routing/Router.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static readonly ReadOnlyDictionary<string, object> _emptyParametersDictionary
5959
[Parameter] public RenderFragment<RouteData> Found { get; set; }
6060

6161
/// <summary>
62-
/// Gets or sets a handler that should be called before navigating to a new page.
62+
/// Gets or sets a handler that should be called before navigating to a new page. Return <c>true</c>
63+
/// if the route's component should be rendered following invocation. Return <c>false</c> otherwise.
6364
/// </summary>
6465
[Parameter] public Func<string, bool> OnNavigate { get; set; }
6566

@@ -107,14 +108,14 @@ public Task SetParametersAsync(ParameterView parameters)
107108
// we need to call the `OnNavigate` handler to ensure that pre-processing
108109
// steps are completed before rendering the route. This way, it will work
109110
// if you navigate to /PageWithLazyLoadedAssemblies or visit it for the first time.
110-
if (OnNavigate != null && !initialOnNavigateCalled) {
111+
if (OnNavigate != null && !initialOnNavigateCalled)
112+
{
111113
OnNavigate(NavigationManager.ToBaseRelativePath(_locationAbsolute));
112114
initialOnNavigateCalled = true;
113115
}
114116

115117
Refresh(isNavigationIntercepted: false);
116118

117-
118119
return Task.CompletedTask;
119120
}
120121

@@ -178,9 +179,11 @@ private void OnLocationChanged(object sender, LocationChangedEventArgs args)
178179
_locationAbsolute = args.Location;
179180
if (_renderHandle.IsInitialized && Routes != null)
180181
{
181-
if (OnNavigate != null) {
182+
if (OnNavigate != null)
183+
{
182184
var continueRender = OnNavigate(NavigationManager.ToBaseRelativePath(_locationAbsolute));
183-
if (!continueRender) {
185+
if (!continueRender)
186+
{
184187
return;
185188
}
186189
}

src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ internal void InitializeDefaultServices()
191191
Services.AddSingleton<IJSRuntime>(DefaultWebAssemblyJSRuntime.Instance);
192192
Services.AddSingleton<NavigationManager>(WebAssemblyNavigationManager.Instance);
193193
Services.AddSingleton<INavigationInterception>(WebAssemblyNavigationInterception.Instance);
194-
Services.AddSingleton<WebAssemblyDynamicResourceLoader>(new WebAssemblyDynamicResourceLoader(DefaultWebAssemblyJSRuntime.Instance));
194+
Services.AddSingleton<WebAssemblyDynamicAssemblyLoader>(new WebAssemblyDynamicAssemblyLoader(DefaultWebAssemblyJSRuntime.Instance));
195195
Services.AddLogging(builder => {
196196
builder.AddProvider(new WebAssemblyConsoleLoggerProvider(DefaultWebAssemblyJSRuntime.Instance));
197197
});

src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyDynamicResourceLoader.cs renamed to src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyDynamicAssemblyLoader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
using System.Runtime.Loader;
1111
using Microsoft.JSInterop.WebAssembly;
1212

13-
namespace Microsoft.AspNetCore.Components.WebAssembly.Services
13+
namespace Microsoft.AspNetCore.Components.WebAssembly
1414
{
15-
public class WebAssemblyDynamicResourceLoader
15+
public class WebAssemblyDynamicAssemblyLoader
1616
{
1717
internal const string GetDynamicAssemblies = "window.Blazor._internal.getDynamicAssemblies";
1818
internal const string ReadDynamicAssemblies = "window.Blazor._internal.readDynamicAssemblies";
1919

20-
private static List<string> _loadedAssemblyCache = new List<string>();
20+
private List<string> _loadedAssemblyCache = new List<string>();
2121

2222
private readonly WebAssemblyJSRuntime _jsRuntime;
2323

24-
internal WebAssemblyDynamicResourceLoader(WebAssemblyJSRuntime jsRuntime)
24+
internal WebAssemblyDynamicAssemblyLoader(WebAssemblyJSRuntime jsRuntime)
2525
{
2626
_jsRuntime = jsRuntime;
2727
}
2828

29-
public async Task<IEnumerable<Assembly>> LoadDynamicAssemblies(IEnumerable<string> assembliesToLoad)
29+
public async Task<IEnumerable<Assembly>> LoadAssembliesAsync(IEnumerable<string> assembliesToLoad)
3030
{
3131
// Only load assemblies that haven't already been lazily-loaded
3232
var newAssembliesToLoad = assembliesToLoad.Where(assembly => !_loadedAssemblyCache.Contains(assembly));

src/Components/test/testassets/BasicTestApp/RouterTest/TestRouterWithDynamicAssembly.razor

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@using Microsoft.AspNetCore.Components.Routing
2-
@using Microsoft.AspNetCore.Components.WebAssembly.Services
2+
@using Microsoft.AspNetCore.Components.WebAssembly
33
@using System.Linq
44
@using System.Reflection
55

6-
@inject WebAssemblyDynamicResourceLoader lazyLoader
6+
@inject WebAssemblyDynamicAssemblyLoader lazyLoader
77

88
<Router AppAssembly="@typeof(BasicTestApp.Program).Assembly" AdditionalAssemblies="@lazyLoadedAssemblies" OnNavigate="@OnNavigate">
99
<Found Context="routeData">
@@ -19,25 +19,33 @@
1919
@code {
2020
private List<Assembly> lazyLoadedAssemblies = new List<Assembly>();
2121

22-
public bool OnNavigate (string uri) {
22+
public bool OnNavigate (string uri)
23+
{
2324
Console.WriteLine($"Running OnNavigate for {uri}...");
2425
_ = LoadAssemblies(uri);
2526
return false;
2627
}
2728

28-
private async Task LoadAssemblies(string uri) {
29+
private async Task LoadAssemblies(string uri)
30+
{
2931
bool loadedAssemblies = false;
30-
try {
31-
if (uri.EndsWith("WithDynamicAssembly")) {
32+
try
33+
{
34+
if (uri.EndsWith("WithDynamicAssembly"))
35+
{
3236
loadedAssemblies = true;
3337
Console.WriteLine($"Loading assemblies for WithDynamicAssembly...");
34-
var assemblies = await lazyLoader.LoadDynamicAssemblies(new List<string>(){ "Newtonsoft.Json.dll" });
38+
var assemblies = await lazyLoader.LoadAssembliesAsync(new List<string>(){ "Newtonsoft.Json.dll" });
3539
lazyLoadedAssemblies.AddRange(assemblies);
3640
}
37-
} catch (Exception e) {
41+
}
42+
catch (Exception e)
43+
{
3844
Console.WriteLine($"Error when loading assemblies: {e}");
39-
} finally {
40-
if (loadedAssemblies) {
45+
}
46+
finally {
47+
if (loadedAssemblies)
48+
{
4149
Console.WriteLine("Calling StateHasChanged...");
4250
StateHasChanged();
4351
}

0 commit comments

Comments
 (0)