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

lodash.throttle

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.throttle

The lodash method `_.throttle` exported as a module.

  • 4.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3M
increased by6.42%
Maintainers
3
Weekly downloads
 
Created

What is lodash.throttle?

The lodash.throttle package is a utility that allows you to rate-limit a function's execution. This can be particularly useful for controlling the rate at which a function that would otherwise be called continuously or very frequently is actually invoked. This is often used in scenarios such as handling scroll, resize, or mousemove events in the browser, where the event can fire many times per second, but you only want to execute a handler function at a controlled rate.

What are lodash.throttle's main functionalities?

Rate-limiting function calls

This feature allows you to limit the number of times a function can be called over time. In the code sample, the `saveInput` function is throttled so that it can only be executed once every 1000 milliseconds, even if the 'input' event is fired more frequently than that.

const _ = require('lodash.throttle');

function saveInput() {
  console.log('Input saved');
}

// Only allow the `saveInput` function to be called once every 1000 milliseconds
const throttledSaveInput = _.throttle(saveInput, 1000);

window.addEventListener('input', throttledSaveInput);

Configuring leading and trailing calls

This feature allows you to control whether the throttled function should be invoked on the leading and/or trailing edge of the wait timeout. In the code sample, the `updatePosition` function is configured to be called at the start of the throttle period (leading edge) but not at the end (trailing edge).

const _ = require('lodash.throttle');

function updatePosition() {
  console.log('Updating position');
}

// Configure the throttle to invoke on the leading edge of the timeout, but not on the trailing edge.
const throttledUpdatePosition = _.throttle(updatePosition, 2000, {
  leading: true,
  trailing: false
});

window.addEventListener('scroll', throttledUpdatePosition);

Other packages similar to lodash.throttle

Keywords

FAQs

Package last updated on 13 Aug 2016

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