Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lodash.debounce

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.debounce

The Lo-Dash function `_.debounce` as a Node.js module generated by lodash-cli.

  • 2.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21M
decreased by-9.16%
Maintainers
4
Weekly downloads
 
Created

What is lodash.debounce?

The lodash.debounce package provides a function that can delay the execution of a function until after wait milliseconds have elapsed since the last time it was invoked. It is useful for implementing behavior that should only happen after a delay, such as waiting for a pause in typing or reducing the frequency of API calls.

What are lodash.debounce's main functionalities?

Debouncing function calls

This code sample shows how to debounce a function that saves input data. The saveInput function will only be called once every 250 milliseconds, no matter how many times the event is triggered.

const debounce = require('lodash.debounce');
const saveInput = debounce((value) => {
  // Save the input value
  console.log('Saving data:', value);
}, 250);
// Will only trigger the saveInput function once every 250ms
document.getElementById('input').addEventListener('keyup', (event) => {
  saveInput(event.target.value);
});

Canceling a debounced call

This code sample demonstrates how to cancel a debounced function call. If the expensiveOperation is debounced and then canceled before the debounce time has elapsed, the function will not be executed.

const debounce = require('lodash.debounce');
const expensiveOperation = debounce(() => {
  // Perform an expensive operation
  console.log('Expensive operation executed');
}, 1000);
expensiveOperation();
expensiveOperation.cancel();

Immediate invocation

This code sample illustrates how to invoke the debounced function immediately on the leading edge of the timeout, without waiting for the trailing edge. The trackEvent function will be called immediately on the first click, but subsequent clicks within 200 milliseconds will not invoke the function again.

const debounce = require('lodash.debounce');
const trackEvent = debounce((event) => {
  // Track the event
  console.log('Event tracked:', event);
}, 200, {
  'leading': true,
  'trailing': false
});
// Will trigger on the leading edge instead of the trailing edge
document.getElementById('button').addEventListener('click', (event) => {
  trackEvent('Button clicked');
});

Other packages similar to lodash.debounce

Keywords

FAQs

Package last updated on 03 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc