Aspnetcore: Eliminate MethodHandle from JS interop APIs, and reference methods by fully-qualified name only

Created on 13 Apr 2018  路  3Comments  路  Source: dotnet/aspnetcore

Possibly consider adding a feature to register a C# method to prevent many calls to Blazor.platform.findMethod()?

const myMethod = Blazor.platform.findMethod(
assemblyName,
namespace,
typeName,
methodName
);
Blazor.platform.RegisterBlazorMethod(myMethod,"UpdateCountFromJavaScript")

area-blazor

Most helpful comment

I guess we could offer an overload of callMethod that takes a string instead of a MethodHandle. The string value would be of the form [AssemblyName]Namespace.TypeName::MethodName(). On the first call we'd do the method handle lookup then call it, and would also cache the method handle under that string key for subsequent invocations.

The only tricky bit would be dealing with multiple method overloads (because the JS side doesn't know about the .NET types in the signature). We might just not support that for the time being.

All 3 comments

Sorry, I don't follow what you're suggesting. Could you give a complete example, showing usage too?

My best guess is that you're suggesting the method would then be callable via a string identifier rather than the method handle. If so that's probably best done in your own application code - if you know you'll need to keep using a method handle, store its value in a const somewhere.

I guess we could offer an overload of callMethod that takes a string instead of a MethodHandle. The string value would be of the form [AssemblyName]Namespace.TypeName::MethodName(). On the first call we'd do the method handle lookup then call it, and would also cache the method handle under that string key for subsequent invocations.

The only tricky bit would be dealing with multiple method overloads (because the JS side doesn't know about the .NET types in the signature). We might just not support that for the time being.

In 0.5.0 the interop APIs are different. We have eliminated the concept of registeredFunction. Now JS functions are just identified by an expression that reaches them globally (e.g., myNamespace.myFunction resolves to window.myNamespace.myFunction).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FourLeafClover picture FourLeafClover  路  3Comments

Kevenvz picture Kevenvz  路  3Comments

markrendle picture markrendle  路  3Comments

bgribaudo picture bgribaudo  路  3Comments

githubgitgit picture githubgitgit  路  3Comments