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")
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).
Most helpful comment
I guess we could offer an overload of
callMethodthat takes astringinstead of aMethodHandle. Thestringvalue 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.