0

I am trying to use the debounce function for setting automatic logout for my application. My understanding is that debounce function will fire the function after the 30 seconds if my application not used. I tried to read the documentation of debounce and feel like I have done the exact something. Am i missing out something? or Is my understanding totally wrong?

var logout_debounce = _.debounce(debounceHandler, 30);
function debounceHandler() {
    location.reload();
}

$("body").on("mousemove", logout_debounce);
Anurag Srivastava
  • 14,077
  • 4
  • 33
  • 43
jenny
  • 277
  • 7
  • 18

2 Answers2

2

The time is in milliseconds so you would need to do 30 * 1000

Dominic
  • 62,658
  • 20
  • 139
  • 163
  • But it does logout on mouse move. I want to get logout automatically if user is idle – jenny Aug 31 '17 at 12:50
  • Not sure what you mean your code works perfectly well, observe if you don't move your mouse for 2secs it will console log "logout" - https://jsfiddle.net/kzj04r5j/1/ – Dominic Aug 31 '17 at 13:03
  • No. It doesn't. I dont see consolelogged out put after 2 seconds if i am idle. – jenny Aug 31 '17 at 13:30
  • yes it does, make sure you're not filtering console messages in your inspector (e.g. to only show errors), and that you trigger a mousemove in the bottom right pane obviously – Dominic Aug 31 '17 at 13:33
1

That 30 is milliseconds, if you want it to be fired after 30 seconds ; you must use 30*1000 = 30000

Atlas
  • 241
  • 3
  • 19