Git Product home page Git Product logo

debounce-fn's Introduction

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.

immediate

Type: boolean
Default: false

Trigger the function on the leading edge instead of the trailing edge of the wait interval. For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.

Related

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

License

MIT © Sindre Sorhus

debounce-fn's People

Contributors

bendingbender avatar sindresorhus avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.