0.1.2 • Published 6 years ago

incoherence v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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)