Ensures that whatToCall is executed with a given tempo.
whatToCall
const rm = rateMinimum({ fallback: () => { return Math.random(); }, whatToCall: (value:number) => { console.log(value); }, interval: { secs: 10 }});// Invokes `whatToCall`, resetting timeoutrm(10);// If we don't call rm() before 'interval' has elapsed,// 'fallback' will be invoked Copy
const rm = rateMinimum({ fallback: () => { return Math.random(); }, whatToCall: (value:number) => { console.log(value); }, interval: { secs: 10 }});// Invokes `whatToCall`, resetting timeoutrm(10);// If we don't call rm() before 'interval' has elapsed,// 'fallback' will be invoked
A practical use for this is to update calculations based on firing of events as well as when they don't fire. For example user input.
// Average distancesconst average = movingAverageLight();const rm = rateMinimum({ interval: { secs: 1 }, whatToCall: (distance: number) => { average(distance); }, // If there are no pointermove events, distance is 0 fallback() { return 0; }})// Report total movemeentdocument.addEventListener(`pointermove`, event => { rm(event.movementX + event.movementY);}); Copy
// Average distancesconst average = movingAverageLight();const rm = rateMinimum({ interval: { secs: 1 }, whatToCall: (distance: number) => { average(distance); }, // If there are no pointermove events, distance is 0 fallback() { return 0; }})// Report total movemeentdocument.addEventListener(`pointermove`, event => { rm(event.movementX + event.movementY);});
Ensures that
whatToCall
is executed with a given tempo.A practical use for this is to update calculations based on firing of events as well as when they don't fire. For example user input.