How to handle rapid events? #1686
-
My use case is a kind of drag and drop API. I was thinking onmousedown attaches both an onmouseup and onmousemove event, which simply updated the x and y coordinates of an SVG. I can easily achieve this using the ShouldRender return type, but am I right to assume this would mean the node would be destroyed and recreated for each invocation of the events? It would be nice if there was some way to directly mutate the DOM. Is this possible with yew? I guess this goes outside the normal use case for the lifecycle hooks. Could I just use raw webassembly code within the component update method? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, Yew uses a virtual DOM approach and, where possible, only updates the existing elements with the required changes. If you do run into performance problems at some point, you can escape from Yew's declarative world and make use of |
Beta Was this translation helpful? Give feedback.
No, Yew uses a virtual DOM approach and, where possible, only updates the existing elements with the required changes.
In your case, when a coordinate changes, Yew basically calls
element.setAttribute("x", new_x_value)
.This doesn't mean that you won't run into performance problems though, but you can check out the Boids example which continuously changes the position and colour of a few hundred
<polygon>
elements (almost) without breaking a sweat.If you do run into performance problems at some point, you can escape from Yew's declarative world and make use of
web-sys
to ac…