javascript - How to do a queue in order to wait 5 seconds to execute a function -


i need put debounce everytime object updated.

here function need solve

updateplayeramount (data) {     this.state.playerslots[data.position - 1].playeramount = data.playeramount;   } 

the param data returns this

{   playeramount : 10,   position     : 2 } 

the playeramount key change value on every click in element.

so:

everytime user clicks on element, amount going change in view, need amount updated every 5 seconds, does't matter whether user clicks 7 times within 2 seconds.

i did settimeout of 5 seconds, issue had, user clicked on element 7 times within 5 seconds, , couldn't see changes 1 one full change once. , need user visualizing changes in view every 5 seconds.

according explanation coworker gave me, need put new changes in array, , listen changes... (?) but, how ?

did ?

ps: using lodash don't how use in case.

update

i did this

  _playeramount = (data) => {     this.state.playerslots[data.position - 1].playeramount = data.playeramount;   }    updateplayeramount (data) {     _.debounce(this._playeramount(data), 5000);   } 

but error in console

uncaught typeerror: expected function

so, recommendations here ?

you need pass .debounce function. right calling this._playeramount(data) , passing return value (undefined) .debounce.

try this:

_.debounce(this._playeramount.bind(this, data), 5000); 

you can do:

var func = this._playeramount; _.debounce(function(){     func(data); }, 5000); 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -