guppy icon indicating copy to clipboard operation
guppy copied to clipboard

Rendering on Mousedown

Open saivan opened this issue 6 years ago • 4 comments

So I noticed in my profiler, every time I click; it calls a guppy click event handler - which then always re-renders and repaints the page. This is probably not ideal behaviour right? The offending function is Guppy.mouse_down, and it seems to go through each guppy instance and re-render it.

I'm not sure that this is ideal behaviour. I think you are perhaps checking the bounding boxes of the element, which in turn; triggers a repaint of the whole page. Thats probably not ideal behaviour.

Solution

Maybe a better way to handle this would be to bind a click handler to the guppy element instead; and only re-render the particular element we clicked on. This would allow you to still have your fancy cursor behaviour, without killing the performance of a page that includes guppy elements.

saivan avatar Dec 28 '18 05:12 saivan

It looks like this is because of the code to deactivate all the other instances that weren't clicked on, since Guppy.deactivate unconditionally re-renders (I guess "in case it got newly deactivated" or something). This should now be fixed.

daniel3735928559 avatar Jan 16 '19 04:01 daniel3735928559

But this will still run a click handler on any click on the page won't it?

saivan avatar Jan 18 '19 10:01 saivan

Yeah--this is intentional, sort of like how for a normal textbox, any other click anywhere else on the page causes it to lose focus. Since we don't have the benefit of the browser defocusing us, we check any click and if it missed all guppy instances, it defocuses the one that's currently focused.

daniel3735928559 avatar Jan 19 '19 02:01 daniel3735928559

Yep. But perhaps we should bind the click handler to the element to focus. Then inside the focus handler, we bind a defocus handler to the whole window. That way, you don't run 100 checks every time we click, if we have 100 guppy boxes

saivan avatar Jan 19 '19 22:01 saivan