In my Vue app, I have a place where I'm setting a timer. I'd like to interrupt the timer if the user presses any key or clicks anywhere in the browser window.
I do not want to stop whatever they clicked from happening. I just want to get a callback whenever it does.
I could just put a function call in every handler, but that is both tedious, sloppy, and not very maintainable.
This is what I'm trying to achieve:
let timerId; const startTheTimer = () => { timerId = setTimeout(() => { somestuff(); timerId = undefined; }, 10000); } // Called whenever any mouse click or keyboard event happens const userDidSomething = () => { if (timerId) { clearTimeout(timerId); timerId = undefined; } } So, my question is, how do I get the function userDidSomething() to be called?
Thanks.