-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Restore public API contract on WebAssemblyJSRuntime #19968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveSandersonMS
merged 2 commits into
blazor-wasm-preview4
from
stevesa/simplify-WebAssemblyJSRuntime-API
Mar 19, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Components/Shared/test/TestWebAssemblyJSRuntimeInvoker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Services; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting | ||
{ | ||
internal class TestWebAssemblyJSRuntimeInvoker : WebAssemblyJSRuntimeInvoker | ||
{ | ||
private readonly string _environment; | ||
|
||
public TestWebAssemblyJSRuntimeInvoker(string environment = "Production") | ||
{ | ||
_environment = environment; | ||
} | ||
|
||
public override TResult InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2) | ||
{ | ||
switch (identifier) | ||
{ | ||
case "Blazor._internal.getApplicationEnvironment": | ||
return (TResult)(object)_environment; | ||
case "Blazor._internal.getConfig": | ||
return (TResult)(object)null; | ||
default: | ||
throw new NotImplementedException($"{nameof(TestWebAssemblyJSRuntimeInvoker)} has no implementation for '{identifier}'."); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntimeExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyJSRuntimeInvoker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.JSInterop.WebAssembly; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebAssembly.Services | ||
{ | ||
/// <summary> | ||
/// This class exists to enable unit testing for code that needs to call | ||
/// <see cref="WebAssemblyJSRuntime.InvokeUnmarshalled{T0, T1, T2, TResult}(string, T0, T1, T2)"/>. | ||
/// | ||
/// We should only use this in non-perf-critical code paths (for example, during hosting startup, | ||
/// where we only call this a fixed number of times, and not during rendering where it might be | ||
/// called arbitrarily frequently due to application logic). In perf-critical code paths, use | ||
/// <see cref="DefaultWebAssemblyJSRuntime.Instance"/> and call it directly. | ||
/// | ||
/// It might not ultimately make any difference but we won't know until we integrate AoT support. | ||
/// When AoT is used, it's possible that virtual dispatch will force fallback on the interpreter. | ||
/// </summary> | ||
internal class WebAssemblyJSRuntimeInvoker | ||
{ | ||
public static WebAssemblyJSRuntimeInvoker Instance = new WebAssemblyJSRuntimeInvoker(); | ||
|
||
public virtual TResult InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2) | ||
=> DefaultWebAssemblyJSRuntime.Instance.InvokeUnmarshalled<T0, T1, T2, TResult>(identifier, arg0, arg1, arg2); | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
src/Components/WebAssembly/WebAssembly/test/Hosting/TestWebAssemblyJSRuntime.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there an important reason to turn all these overloads into extension methods? If there was we can change it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It loosely follows the pattern we have with IJSRuntime - https://github.com/dotnet/aspnetcore/blob/master/src/JSInterop/Microsoft.JSInterop/src/JSRuntimeExtensions.cs#L13 where the most extensive overload was declared in the base class. It would have made sense to keep these as extensions if derived types had to implement every overload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks. Since we’re no longer making these methods overridable, that no longer applies, so I’ll leave them as regular instance methods.