Socket
Book a DemoInstallSign in
Socket

micro-debounce

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro-debounce

Debounce functions using micro tasks

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

micro-debounce

Debounce a function using microtasks.

Install

npm install micro-debounce

Useage

Queue a function to execute at the end of an execution loop.

import debounce from 'micro-debounce';

function resize(a) {
  console.log('resize!!!', a);
}

const debouncedResize = debounce(resize);

debouncedResize(1);
debouncedResize(2);
debouncedResize(3);
debouncedResize(4);
debouncedResize(5);

console.log('beforeResize');

Our log looks like this:

  • "beforeResize"
  • "resize!!!" 5

If we didn't debounce we would end up with this:

  • "resize!!!" 1
  • "resize!!!" 2
  • "resize!!!" 3
  • "resize!!!" 4
  • "resize!!!" 5
  • "beforeResize"

Options

leading=false (boolean)

Whether the arguments are passed to the function from the leading function vs the last function.

import debounce from 'micro-debounce';

function resize(a) {
  console.log('resize!!!', a);
}

const debouncedResize = debounce(resize, { leading: true });

debouncedResize(1);
debouncedResize(2);
debouncedResize(3);
debouncedResize(4);
debouncedResize(5);

console.log('beforeResize');

Our log looks like this:

  • "beforeResize"
  • "resize!!!" 1

Promise=Promise (Object)

The promise implementation to use. Uses the global Promise by default.

Why?

Useful when the same function is called multiple times within the same execution context. Enjoy!

Keywords

debounce

FAQs

Package last updated on 06 Apr 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