Metal Debounce Utility

2.0.2 · abandoned · verified Sun Apr 19

metal-debounce is a utility library providing a debounce function, originally part of the deprecated Metal.js framework. It delays the execution of a function until a specified time has elapsed since its last invocation, a common pattern for optimizing event handlers (e.g., input, resize, scroll) by preventing excessive calls. The current stable version is 2.0.2, last published approximately seven years ago. As the Metal.js framework itself is no longer actively maintained for open-source releases, this package should be considered abandoned. It likely targets older JavaScript environments and CommonJS modules, lacking modern features like native ESM support or TypeScript definitions. Alternatives like `lodash.debounce` or `debounce-fn` offer more robust and actively maintained solutions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the `debounce` function to limit repeated calls, such as from rapid user input.

const debounce = require('metal-debounce');

function logActivity(message) {
  console.log(`Activity: ${message} at ${new Date().toLocaleTimeString()}`);
}

// Create a debounced version of logActivity that waits 500ms
const debouncedLog = debounce(logActivity, 500);

console.log('Simulating rapid events...');
debouncedLog('Event 1');
debouncedLog('Event 2');
debouncedLog('Event 3');

setTimeout(() => {
  console.log('Waiting 600ms after last debounced call...');
  debouncedLog('Event 4 (should trigger)');
}, 600);

setTimeout(() => {
  console.log('Simulating more rapid events after initial trigger...');
  debouncedLog('Event 5');
  debouncedLog('Event 6');
}, 1200);

setTimeout(() => {
  console.log('Final wait...');
}, 2000);

view raw JSON →