Skip to content

rickkky/incoherence

Repository files navigation

incoherence

npm version Commitizen friendly

Install

npm i -S incoherence

Comparison

Here is an example to show the difference between regular, debounced and throttled invocations: Visual comparison.

API

debounce

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>

throttle

function throttle<A extends [], R>(
  func: (...args: A) => R,
  gap?: number = 128,
): (this: any, ...args: A) => Promise<R>

Examples

import { debounce, throttle } from 'incoherence'

window.onresize = throttle(() => {
  console.log(window.innerWidth, window.innerHeight)
}, 100)