-
Notifications
You must be signed in to change notification settings - Fork 64
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
Bug: Plugin is calling changeDetection on every mousemove #92
Comments
So CD actually has to be triggered when the mouse moves, because otherwise the select box won't be re-rendered on the screen and it becomes janky if I audit / throttle it. Curious to hear your thoughts tho. |
Ok I see, I haven't had a lot of time this week to look at all the code but I'll have a check this weekend and get back to you. If you can tell me more precisely how change detection affects re-rendering (point me to some code) that would make it faster. |
A nice optimisation for performance would be to subscribe on mousemove only between mousedown and mouseup. |
Good point @bertrandg! I like that. But as I said, we won't be able to run this outside of Angular zone because otherwise the UI won't be updated properly and the selection box won't be re-drawn and throttling it will make it janky. If I remember correctly this is something I tried when I initially built this lib. |
Yeah I understand. Subscribing on But to go deeper, it would be possible to track all mouse events outside zone.
|
Yep, sounds reasonable. I ll have a look and see which solution I ll go with. Maybe deteching the whole container from the CD cycle might be a good idea. This way I can call CD manually when needed. |
Hi, 2 - SelectContainerComponentin class use : But this don't solve problem about mouseevents on container triggers CD I will study EventManagerPlugin to run outsideAngularZone and how integrate it in project, but it is a little hard for me now |
Any news on this ? |
Hey @Saonela, my apologies but I haven't had the time yet to delve into this. I am a bit swamped at the moment but if you want to take a stab at it I am more than happy to support you. I would appreciate a PR. First we should upgrade the library to v9 tho. That is also on my todo list. |
Reproduction: https://stackblitz.com/edit/ngx-drag-to-select-2bpbcb
If you check the console you will see that every time the mouse moves, the test function is called as a result of change detection. This can be easily fixed by running the plugin outside angular to avoid change detection from eventlisteners.
Event listener:
const mousemove$ = fromEvent<MouseEvent>(window, 'mousemove').pipe( filter(() => !this.disabled), share() );
ngx-drag-to-select/projects/ngx-drag-to-select/src/lib/select-container.component.ts
Line 157 in c47dee4
The text was updated successfully, but these errors were encountered: