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

ts-debounce

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-debounce

TypeScript implementation of debounce

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
131K
decreased by-2.65%
Maintainers
1
Weekly downloads
 
Created

What is ts-debounce?

The ts-debounce npm package provides a simple and efficient way to debounce functions in TypeScript. Debouncing is a programming practice used to ensure that time-consuming tasks do not fire so often, improving performance and user experience.

What are ts-debounce's main functionalities?

Basic Debounce

This feature allows you to debounce a function, ensuring it only executes after a specified delay. In this example, the `saveInput` function will only be called 300 milliseconds after the last input event.

const { debounce } = require('ts-debounce');

function saveInput() {
  console.log('Saving data');
}

const debouncedSaveInput = debounce(saveInput, 300);

document.getElementById('input').addEventListener('input', debouncedSaveInput);

Debounce with Immediate Execution

This feature allows you to debounce a function but execute it immediately on the first call. Subsequent calls within the delay period will be ignored. In this example, `fetchData` will be called immediately on the first input event, and then debounced for 300 milliseconds.

const { debounce } = require('ts-debounce');

function fetchData() {
  console.log('Fetching data');
}

const debouncedFetchData = debounce(fetchData, 300, { isImmediate: true });

document.getElementById('input').addEventListener('input', debouncedFetchData);

Cancel Debounce

This feature allows you to cancel a debounced function call. In this example, the `logMessage` function will be debounced for 300 milliseconds, but if the cancel button is clicked, the debounce will be cancelled.

const { debounce } = require('ts-debounce');

function logMessage() {
  console.log('Logging message');
}

const debouncedLogMessage = debounce(logMessage, 300);

document.getElementById('input').addEventListener('input', debouncedLogMessage);

document.getElementById('cancelButton').addEventListener('click', () => {
  debouncedLogMessage.cancel();
  console.log('Debounce cancelled');
});

Other packages similar to ts-debounce

Keywords

FAQs

Package last updated on 10 Jan 2021

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