dooblr
dooblr

Reputation: 478

_lodash debounce not debouncing

Here is my code (angular 2):

<button (click)="click()">GO!</button>

debouncedFunc = _.debounce(()=>{
    console.log('bam')
  }, 1000, {"leading":true})

click(){
  this.debouncedFunc()
}

this fires off every event with no debouncing. I want to only hit my endpoint max once per second and ignore all others. What am I missing? Thanks.

Upvotes: 0

Views: 903

Answers (1)

dooblr
dooblr

Reputation: 478

Figured it out 10 seconds after posting this. Funny how that works. All options needed to be declared:

 <button (click)="click()">GO!</button>

 debouncedFunc = _.debounce(()=>{
   console.log('bam')
 }, 1000, {"leading":true,"trailing":false})

 click(){
   this.debouncedFunc()
 } 

Upvotes: 2

Related Questions