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

debounce-queue

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debounce-queue

Like lodash.debounce but you get an array of all previous (unique) events

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
614
decreased by-4.95%
Maintainers
1
Weekly downloads
 
Created
Source

debounce-queue

npm

Like lodash.debounce but you get an array of all previous (unique) events instead of just the last/first one.

Example

import {watch} from 'chokidar';
import debounce from 'debounce-queue';

function onChange(files) {
  // files is now an array of (unique) files that were changed since (t-1000)ms
}

const debounced = debounce(onChange, 1000);

watch('.')
  .on('change', debounced)

You can customize which items get enqueued:

const debounced = debounce(onChange, 1000, {
  enqueue( data, queue, defaultEnqueue ) {
    if ( queue.indexOf( data ) === -1 ) {
      queue.push( data )
    }
    return queue;
  }
});

Options

sleep (boolean) (default: false)

Sleeps while callback is being awaited. Helps prevent feedback loop when a process modifies files in the same path it's watching for changes.

Be sure to return a promise in your callback.

Extras

Promise support

Your debounced function can return a promise

function onChange(files) {
  return Promise.map(files, () => {
    return Promise.delay(1000);
  });
  // Next onChange will fire after `delay + files.length * 1000` ms
}

FAQs

Package last updated on 30 Jan 2017

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