roderickhsiao / idle-tracker

Javascript library to track browser inactivity
https://roderickhsiao.github.io/idle-tracker/test/
MIT License
15 stars 3 forks source link

`end` method does not remove event listeners #8

Closed mbicknese closed 5 years ago

mbicknese commented 5 years ago

Calling the end method on the tracker instance does not correctly remove the listeners. I would have submitted a solution, but I cannot get puppeteer to work on Windows.

Suggested solution, apply following patch

+++ b/src/index.js
@@ -26,8 +26,9 @@ class IdleTracker {

   start = ({ onIdleCallback } = {}) => {
     this.callback = onIdleCallback || this.callback;
+    this.handleEvent = this.handleEvent.bind(this);
     this.listeners = this.events.map(eventName => {
-      document.addEventListener(eventName, this.handleEvent.bind(this), false);
+      document.addEventListener(eventName, this.handleEvent, false);
       return eventName;
     });
roderickhsiao commented 5 years ago

ah, the context. Thanks! Will take a look in a bit

roderickhsiao commented 5 years ago

Publish 0.0.6 Thanks!

https://github.com/roderickhsiao/idle-tracker/releases/tag/0.0.6