debounce-fn
Debounce a function
Last updated 8 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install debounce-fn 
SYNC missed versions from official npm registry.

debounce-fn Build Status

Debounce a function

Install

$ npm install debounce-fn

Usage

const debounceFn = require('debounce-fn');

window.onresize = debounceFn(() => {
	// Do something on window resize
}, {wait: 100});

API

debounceFn(input, options?)

Returns a debounced function that delays calling the input function until after wait milliseconds have elapsed since the last time the debounced function was called.

It comes with a .cancel() method to cancel any scheduled input function calls.

input

Type: Function

Function to debounce.

options

Type: object

wait

Type: number
Default: 0

Time to wait until the input function is called.

before

Type: boolean
Default: false

Trigger the function on the leading edge of the wait interval.

For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.

after

Type: boolean
Default: true

Trigger the function on the trailing edge of the wait interval.

Related

  • p-debounce - Debounce promise-returning & async functions

Current Tags

  • 4.0.0                                ...           latest (8 months ago)

8 Versions

  • 4.0.0                                ...           8 months ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 1.0.0                                ...           3 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.0                                ...           6 years ago
  • 0.0.1-security                                ...           5 years ago
  • 2.0.0                                ...           5 years ago

Copyright 2014 - 2016 © taobao.org |