-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Dynamic root components 'EventCallback' parameter support #35206
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
Conversation
|
@SteveSandersonMS I've made some changes to centralize the code that determines whether a parameter is an event callback. My approach may have differed slightly from what you had in mind, so let me know if you would prefer it be done in a different way. The biggest change I made to get this to work was providing component parameter info to JS in |
src/Components/Web.JS/src/Rendering/WebRendererInteropMethods.ts
Outdated
Show resolved
Hide resolved
|
This is looking really good to me!
No, looks solid.
I admit I hadn't thought through that particular consequence, but it doesn't seem problematic and the way you've implemented it is clear. Thinking about it more, the previous "optimization" about not supplying parameter infos when there was no initializer would only take effect in really edge-case scenarios, and it would probably be inevitable in the long run that we'd have reasons to pass through parameter infos for whatever future functionality we end up building in this area. So in retrospect I don't think there was much of a good reason to be trying to skip passing that info, and what you have done here is clearer than we had before. |
|
@SteveSandersonMS Thanks for the feedback! I've just updated the implementation to support the parameter reassignment scenarios (including setting parameters to |
SteveSandersonMS
left a comment
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.
Fantastic - this looks ideal! Thanks for getting it into such good shape.
Dynamic root components
EventCallbackparameter supportJavaScript functions can now be passed as parameters to Blazor dynamic root components. The motivating scenario for this is allowing event callbacks in Blazor components to be handled by functions defined in JavaScript. The supported .NET parameter types are
EventCallbackandEventCallback<TValue>.PR Description
Using this feature is as simple as passing a normal JS function as a parameter to a dynamic root component. Under the hood, parameters of 'function' type are wrapped in
JSObjectReferenceinstances before being sent to .NET. The lifetime of these instances is automatically scoped to the lifetime of the dynamic root component.On the .NET side, deserializing parameters into types
EventCallbackandEventCallback<TValue>is special-cased; the parameters are assignedEventCallbacks that invoke the provided JS function from the deserializedJSObjectReference.Fulfills some requirements for #35112