Debounce a function
$ npm install @f/debounce
Debounce takes a function and a time in milliseconds and returns a function that, once called, will not run until
time milliseconds have elapsed and will drop all subsequent calls in the interim period. This is useful if you have an event that might happen many times in a short period but that you only want to respond to once after they have all stopped, e.g.
var debounce = require('@f/debounce') window.addEventListener('resize', debounce(relayout))
fn- The function you want to debounce
time- The time in milliseconds. Defaults to 0.
Returns: A debounced version of
fn. Each time
fn is called, it will return a
cancel function that you can use to cancel the invocation of