moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
315 stars 128 forks source link

Improve scrolling performance with passive event listeners #58

Closed bygrace1986 closed 6 years ago

bygrace1986 commented 7 years ago

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/HackedByChinese/ng2-idle/blob/master/CONTRIBUTING.md#getting-help

Current behavior Adding default list of event listeners (DEFAULT_INTERRUPTSOURCES) causes warnings in Angular4. EX: [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive. [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.

Expected behavior Add event listeners in passive mode.

Minimal reproduction of the problem with instructions const idle = new Idle(); idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); idle.watch();

What is the motivation / use case for changing the behavior? Improved performance.

moribvndvs commented 6 years ago

Implemented in a5e24eb. However, this has to be manually enabled by your application, and should do so based on whether or not you detect the browser supports this feature (since not all will).

I did not want to build feature detection into this module as it is out of scope, but instead leave that up to you. However, I've added a function that you can use in concert with the feature detection of your choice so you can still utilize default interrupt sources. More info here.

Simply change to the following (this example uses detectIt):

const idle = new Idle();
idle.setInterrupts(createDefaultInterruptSources({passive: detectIt.passiveEvents});
idle.watch();