-
-
Notifications
You must be signed in to change notification settings - Fork 828
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
Add the onresize
event handler to Element
#2479
Conversation
Thanks for the PR! Sorry this languished. Did a review with Evan today and we had some thoughts:
Since you already have the knowledge for this PR, maybe you want to follow this up with |
Thanks for your review.
I was not aware of this change. I will rename
Ok.
Indeed. I'll make you a suggestion.
I agree that we should mention that in the documentation. However, I don’t think I understood how an Option could help to save performance: if I'm not mistaken, a new Observer is only created, and resize events raised, when a component declares a
Good idea. Sure. Before that, we should clarify what are your expectations for the options structs. Is it related to your previous comment? |
For now, the application must define which field ( |
onresized
event handler to Elementonresize
event handler to Element
For performance, I'm just worried about dumping tons of onresize events into the VirtualDom when the window resizes. If many elements are listening to this event, we'll have a lot of processing. I'm not sure what the actual performance here is like - if it's actually bad - but we might want to provide some nudges in our doc-comments outlining that it could lead to lag/flickering if used too liberally.
For web, let's try and keep it "lazy" and for desktop It hink it's okay to call getComputedStyle on the element.
ResizeObservers in JS have room for an options object that AFAIK is not actually used for anything. The onvisible impl will likely rely on IntersectionObserver which does have options (percent visibility...) which we won't be able to plumb into the observer using the declarative approach. Maybe one day we'll implement the imperative analog with all the options, but for both resized and visible we won't be able to pass in any extra constructor options with our current rsx! syntax. |
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.
Thanks for adding this! I tweaked the event to make it fit a bit more closely with our other events. We have a trait on the web renderer to downcast events to the web-sys counterparts. I removed the wrapper around the observer size so we can implement that trait with a web-sys type.
I also added an example and tested on all platforms. It seems like this approach is pretty fast. I am getting ~16ms between the event being sent on desktop and the render being sent back
This PR add the capability to handle the resize event for a given
Element
:It should give an answer to #1346.