npm i -S incoherence
Here is an example to show the difference between regular, debounced and throttled invocations: Visual comparison.
function debounce<A extends [], R>(
func: (...args: A) => R,
gap?: number = 128,
options?: Partial<{
maxGap: number
immediate: boolean
}> = {
maxGap: Infinity,
immediate: true,
},
): (this: any, ...args: A) => Promise<R>
function throttle<A extends [], R>(
func: (...args: A) => R,
gap?: number = 128,
): (this: any, ...args: A) => Promise<R>
import { debounce, throttle } from 'incoherence'
window.onresize = throttle(() => {
console.log(window.innerWidth, window.innerHeight)
}, 100)